#include <bits/stdc++.h>
using namespace std;
const long long p=1e9+7;
int tt,c,n,m,tag[100010],pd1=1,pd2=1;
long long jc[100010];
vector<int> G[100010];
struct edge{
	int u,v;
}e[100010];
long long dfs(int u,int fa){
	long long res=jc[G[u].size()-1];
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];
		if(v==fa) continue ;
		res=res*dfs(v,u)%p;
	}
	return res;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>tt;jc[0]=1;
	for(int i=1;i<=100000;i++) jc[i]=jc[i-1]*i%p;
	while(tt--){pd1=1,pd2=1;//cout<<"ak";
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++) G[i].clear();
		for(int i=1;i<n;i++){
			int u,v;
			scanf("%d%d",&u,&v);
			e[i]={u,v};
			G[u].push_back(v);
			G[v].push_back(u);
			pd1&=(u+1==v);
			pd2&=(u==1);
		}
		for(int i=1;i<=m;i++) scanf("%d",&tag[i]);
		if(pd1||n==2){
			printf("1\n");
			continue ;
		}
		if(pd2){
			printf("%lld\n",(p+jc[n-2]*m%p-1ll*m*(m-1)/2%p*jc[n-3]%p)%p);
			continue ;
		}
		if(m==1){
			printf("%lld\n",dfs(e[tag[1]].u,0));
			continue ;
		}
		//printf("%lld\n",(dfs(e[tag[1]].u,0)+dfs(e[tag[2]].v,0))%p);
	}
	return 0;
}

