#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=100010,mo=1e9+7;
int q,c,n,a,b,x,k,cnt,h[N];
LL ans,jc[N],s[N];
struct AB{
	int x,y,n;
}l[N*2];
void in(int x,int y){
	l[++cnt].x=x,l[cnt].y=y;
	l[cnt].n=h[x];h[x]=cnt;
}
void dfs(int a,int p){
	int b,t=0;
	for(int i=h[a];i;i=l[i].n){
		b=l[i].y;
		if(b==p)continue;
		t++,dfs(b,a);
		s[a]=s[a]*s[b]%mo;
	}
	s[a]=s[a]*jc[t]%mo;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&q);
	jc[0]=1;
	for(int i=1;i<=N-10;i++){
		jc[i]=jc[i-1]*i%mo;
	}
	while(q--){
		scanf("%d%d",&n,&k);
		cnt=0,ans=1;
		for(int i=1;i<=n;i++)h[i]=0,s[i]=1;
		for(int i=1;i<n;i++){
			scanf("%d%d",&a,&b);
			in(a,b),in(b,a);
		}
		for(int i=1;i<=k;i++){
			scanf("%d",&x);
		}
		if(c==18){
			printf("1\n");
			continue;
		}
		if(c>=19&&c<=21){
			ans=k*jc[n-2]%mo;
			if(k>=2)ans-=k*(k-1)/2%mo*jc[n-3];
			printf("%lld\n",(ans%mo+mo)%mo);
			continue;
		}
		a=l[x*2].x,b=l[x*2].y;
		dfs(b,a);
		ans=s[b];
		dfs(a,b);
		ans=ans*s[a]%mo;
		printf("%lld\n",ans);
	}
	return 0;
}
