#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,mod=1e9+7;
int c,T,n,k,ky[N],u[N],v[N];
long long ans,jc[N];
vector<int> e[N];
long long dfs(int u,int fa){
	long long ans=1;
	for(int i=0;i<e[u].size();i++){
		if(i==fa)continue;
		ans=(ans*dfs(i,u))%mod;
	}
	ans=(ans*jc[e[u].size()-2])%mod;
	return ans;
}
void init(){
	jc[1]=1;
	for(int i=2;i<N;i++){
		jc[i]=(i*jc[i-1])%mod;
	}
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&T);
	init();
	while(T--){
		for(int i=1;i<=n;i++) e[i].clear();
		scanf("%d%d",&n,&k);
		for(int i=1;i<n;i++) {
			scanf("%d%d",&u[i],&v[i]);
			e[u[i]].push_back(v[i]);
			e[v[i]].push_back(u[i]);
		}
		for(int i=1;i<=k;i++) {
			scanf("%d",&ky[i]);
			ans=(ans*dfs(u[ky[i]],v[ky[i]]))%mod;
			dfs(v[ky[i]],u[ky[i]]);
		}
		printf("%lld\n",ans);
	}
	return 0;
}

