#include<bits/stdc++.h>
const int N=1e5+10,MOD=1e9+7;
int nx[N*2],ls[N],to[N*2],fr[N*2],tot;
void add(int u,int v){
	nx[++tot]=ls[u];
	to[ls[u]=tot]=v;
	fr[tot]=u;
}
int sc[N],ans,fac[N],e2;
bool dfs(int u,int fa){
	sc[u]=0;bool ret=0;
	for(int i=ls[u];i;i=nx[i]){
		if(to[i]==fa) continue;
		if(dfs(to[i],u)) ret=1;
		else ++sc[u];
	}
	if(ret) ans=1ll*ans*fac[sc[u]]%MOD*sc[u]%MOD;
	else ans=1ll*ans*fac[sc[u]]%MOD;
	for(int i=ls[u];i;i=nx[i]) if(to[i]!=fa&&(i+1)/2==e2) ret=1;
	return ret;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%MOD;
	int c,T;scanf("%d%d",&c,&T);
	while(T--){
		int n,k;scanf("%d%d",&n,&k);
		memset(ls,0,sizeof ls),tot=0;
		for(int i=1,u,v;i<n;i++) scanf("%d%d",&u,&v),add(u,v),add(v,u);
		int e;
		if(k!=2) while(k--) scanf("%d",&e);
		else scanf("%d%d",&e,&e2);
		ans=1;
		dfs(fr[e*2-1],to[e*2-1]);
		dfs(to[e*2-1],fr[e*2-1]);
		printf("%d\n",ans);
	}
}
