#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const ll inv2=(mod+1)>>1;
ll read(){
	ll x=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return x;
}
ll ksm(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res;
}
ll inv(ll x){
	return ksm(x,mod-2);
}
const ll maxn=1e5+10;
ll n,k,head[maxn],tot,s[maxn],t[maxn],d[maxn],fac[maxn],ans,bk[maxn],sum[maxn],cnt[maxn];
struct edge{
	ll t,nxt,id;
}e[maxn<<1];
void add(ll u,ll v,ll id){
	e[++tot]={v,head[u],id};
	head[u]=tot;
}
void init(){
	for(ll i=1;i<=n;i++) head[i]=d[i]=bk[i]=sum[i]=cnt[i]=0;
	tot=0;
}
void dfs(ll u,ll fa){
	for(ll i=head[u];i;i=e[i].nxt){
		if(e[i].t==fa) continue;
		dfs(e[i].t,u);
		if(sum[e[i].t]||bk[e[i].id]) sum[u]++;
		cnt[u]+=cnt[e[i].t]+bk[e[i].id];
	}
}
void solve(){
	n=read(),k=read();
	init();
	for(ll i=1;i<n;i++){
		s[i]=read(),t[i]=read();
		add(s[i],t[i],i),add(t[i],s[i],i);
		d[s[i]]++,d[t[i]]++;
	}
	ans=1;
	ll rt=0;
	while(k--){
		ll x=read();
		bk[x]=1;
		rt=x;
	}
	dfs(1,0);
	for(ll i=1;i<=n;i++){
		if(d[i]<=2) continue;
		ll c=sum[i];
		if(cnt[1]-cnt[i]) c++;
		// cout<<i<<" "<<c<<"\n";
		ll tmp=(d[i]-c)*(d[i]-c-1)%mod*fac[d[i]-2]%mod*inv2%mod;
		ans=ans*((fac[d[i]]*inv2%mod-tmp+mod)%mod)%mod;
	}
	cout<<ans<<"\n";
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=1;
	for(ll i=1;i<=100000;i++) fac[i]=fac[i-1]*i%mod;
	ll c=read(),t=read();
	while(t--) solve();
}