#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<numeric>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e5+10;
const int N=1e5;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int inv2=(mod+1)>>1;
inline int qpow(int x,int y){
	int res=1;
	while(y)
	{
		if(y&1){
			res=1ll*res*x%mod;
		}
		y>>=1;
		x=1ll*x*x%mod;
	}
	return res;
}
int n,k,ans;
basic_string <int> tr[MAXN];
int deg[MAXN],dad[MAXN];
inline void add_edge(int x,int y){
	tr[x].push_back(y);
}
void dfs(int x){
	for(int to:tr[x])
	{
		if(to^dad[x]){
			dad[to]=x;
			dfs(to);
		}
	}
}
int u[MAXN],v[MAXN];
bool val[MAXN];
int fac[MAXN];
inline void init(){
	fac[0]=1;
	for(int i=1;i<=n;i++)
	{
		fac[i]=1ll*fac[i-1]*i%mod;
	}
}
namespace flower{
	inline bool check(){
		for(int i=1;i<n;i++)
		{
			if(u[i]^1||v[i]^(i+1)){
				return false;
			}
		}
		return true;
	}
	inline void solve(){
		ans=1ll*k*fac[n-3]%mod*(n-1-k)%mod;
		ans=(ans+(1ll*k*(k-1)/2)%mod*fac[n-3])%mod;
		printf("%d\n",ans);
	}
}
namespace chain{
	inline bool check(){
		for(int i=1;i<n;i++)
		{
			if(u[i]^i||v[i]^(i+1)){
				return false;
			}
		}
		return true;
	}
	inline void solve(){
		puts("1");
	}
}
inline void solve(){
	scanf("%d%d",&n,&k);
	init();
	memset(deg,0,sizeof(int)*(n+1));
	for(int i=1;i<=n;i++)
	{
		tr[i].clear();
	}
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		deg[x]++;
		deg[y]++;
		add_edge(x,y);
		add_edge(y,x);
		u[i]=x;
		v[i]=y;
	}
	memset(val,0,sizeof(bool)*(n+1));
	for(int i=1;i<=k;i++)
	{
		int x;
		scanf("%d",&x);
		val[x]=true;
	}
	if(k==1){
		ans=1;
		for(int i=1;i<=n;i++)
		{
			ans=1ll*ans*fac[deg[i]-1]%mod;
		}
		printf("%d\n",ans);
		return ;
	}
	if(flower::check()){
		flower::solve();
		return ;
	}
	if(chain::check()){
		chain::solve();
		return ;
	}
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	#ifdef LOCAL
	atexit([](){fprintf(stderr,"%.3lfs\n",(double)clock()/CLOCKS_PER_SEC);});
	#endif
	int t;
	scanf("%*d%d",&t);
	while(t--)
	{
		solve();
	}
	return 0;
}