#include<bits/stdc++.h>
#define int long long//
using namespace std;
const int mod=1e9+7;
const int inv2=5e8+4;
const int N=1e5;
int C,T,n,k,e[100010],h[100010],to[200010],nxt[200010],cnt;
int fac[100010],f[100010];
void inst(int x,int y){
	to[++cnt]=y,nxt[cnt]=h[x],h[x]=cnt;
}
void init(){
	for(int i=0;i<=n+3;i++)h[i]=f[i]=0;
	cnt=0;
}
void dfs(int x,int fa){
	f[x]=1;
	int t=0;
	for(int i=h[x];i;i=nxt[i]){
		int y=to[i];
		if(y!=fa){
			dfs(y,x);
			t++,f[x]=f[x]*f[y]%mod;
		}
	}
	f[x]=f[x]*fac[t]%mod;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&C,&T);
	fac[0]=1;
	for(int i=1;i<=N;i++)
		fac[i]=fac[i-1]*i%mod;
	while(T--){
		init();
		scanf("%lld%lld",&n,&k);
		for(int i=1,x,y;i<n;i++){
			scanf("%lld%lld",&x,&y);
			inst(x,y),inst(y,x);
		}
		for(int i=1;i<=k;i++)
			scanf("%lld",&e[i]);
		if(C==18){
			printf("1\n");
		}
		if(19<=C&&C<=21){
			int res=((n-k-1)*k+k*(k-1)/2)%mod*fac[n-3]%mod;
			printf("%lld\n",res);
		}
		if(1<=C&&C<=6){
			int u=to[e[1]*2],v=to[e[1]*2-1];
			dfs(u,v),dfs(v,u);
			printf("%lld\n",f[u]*f[v]%mod);
		}
	}
	return 0;
}
