#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll M=2e5+5,mod=1e9+7;
ll rd(){
	ll res=0;
	char c=getchar();
	while(c>'9'||c<'0')c=getchar();
	while(c<='9'&&c>='0')res=res*10+c-'0',c=getchar();
	return res;
}
ll fp(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1)res=(res*x)%mod;
		x=(x*x)%mod,y/=2;
	}
	return res;
}
ll c,t,n,k,u,v,ans,ni[M],jie[M],dp[M],fan[M],nidp[M],tdp[M];
ll cnt,nxt[M],hd[M],to[M],f[M],ask,sz[M],vis[M],gan[M],cmm;
void lian(ll x,ll y){
	nxt[++cnt]=hd[x];
	hd[x]=cnt;
	to[cnt]=y;
	nxt[++cnt]=hd[y];
	hd[y]=cnt;
	to[cnt]=x;
}
void dfs1(ll x){
	ll sum=0;
	dp[x]=1;
	for(int i=hd[x];i;i=nxt[i]){
		ll y=to[i];
		if(y==f[x])continue;
		f[y]=x;
		dfs1(y);
		sz[x]++;
		dp[x]=(dp[x]*dp[y])%mod;
	}
	dp[x]=(dp[x]*jie[sz[x]])%mod;
	nidp[x]=fp(dp[x],mod-2);
	tdp[x]=dp[x];
}
void dfs2(ll x){
//	if(vis[x]){
//		cout<<++cmm<<endl;
////		if(flg)cout<<"flag"<<endl;
//	}
	if(x==1){
		fan[x]=1;
	}else{
		if(f[x]==1){
//			if(vis[x])cout<<"FA=1"<<endl; 
			if(sz[1]==1){
				fan[x]=1;
			}else{
				fan[x]=tdp[1]*ni[sz[1]-1]%mod*ni[sz[1]-gan[1]]%mod*(sz[1]-1-gan[1])%mod*nidp[x]%mod;
			}
		}else{
			if(!vis[f[x]]){
				fan[x]=fan[f[x]]*tdp[f[x]]%mod*nidp[x]%mod;
			}else{
//				if(vis[x])cout<<"shuang"<<endl;
				fan[x]=fan[f[x]]*tdp[f[x]]%mod*nidp[x]%mod*ni[sz[f[x]]-gan[f[x]]]%mod*(sz[f[x]]-gan[f[x]]-1)%mod;
			}
		}
	}
	if(vis[x])ans=(ans+dp[x]*fan[x])%mod;
	for(int i=hd[x];i;i=nxt[i]){
		ll y=to[i];
		if(y==f[x])continue;
		dfs2(y);
		tdp[x]=tdp[x]*nidp[y]%mod*tdp[y]%mod;
		if(vis[y]){
			gan[x]++;
			tdp[x]=tdp[x]*ni[sz[x]-gan[x]+1]%mod*(sz[x]-gan[x])%mod;
		}
	} 
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	jie[0]=1;
	ni[1]=1;
	for(int i=2;i<M;++i){
		ni[i]=(mod-mod/i)*ni[mod%i]%mod;
	}
	for(ll i=1;i<M;++i)jie[i]=(jie[i-1]*i)%mod;
	c=rd(),t=rd();
//	cout<<c<<endl;
	while(t--){
//		scanf("%lld%lld",&n,&kendl;
		n=rd(),k=rd();
//		cout<<n<<' '<<k<<endl;
		cnt=ans=0;
		fan[0]=1;
		for(int i=1;i<=n;++i){
			hd[i]=f[i]=sz[i]=vis[i]=gan[i]=0;
		}
		for(int i=1;i<n;++i){
			u=rd(),v=rd();
			lian(u,v);
		}
//		cout<<"adddone";
		dfs1(1);
//		cout<<"dfs1done";
//		for(int i=1;i<=n;++i)printf("dp[%d]=%lld\n",i,dp[i]);
		for(int i=1;i<=k;++i){
			ask=rd();
			u=to[ask*2-1],v=to[ask*2];
			if(f[u]==v)vis[u]=1;
			else vis[v]=1;
		}
		dfs2(1);
//		cout<<"dfs2done";
//		for(int i=1;i<=n;++i)printf("fan[%d]=%lld\n",i,fan[i]);
		printf("%lld\n",ans);
	}
	return 0;
}
/*
1 1
7 2
1 2
1 3
1 4
4 5
4 6
1 7
1 4
*/

