#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5,M=1e9+7;
int T,c,n,m,k,rt1,rt2;
ll ans;
ll jc[N],dp[N];
vector<int>vec[N];
struct A{
	int u,v;
}e[N];
void dfs(int u,int fa){
	dp[u]=jc[vec[u].size()-1];
	for(int v:vec[u]){
		if(v==fa)continue;
		dfs(v,u);
		dp[u]=dp[u]*dp[v]%M;
	}
}
void solve(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)vec[i].clear();
	for(int i=1;i<n;i++){
		scanf("%d%d",&e[i].u,&e[i].v);
		vec[e[i].u].push_back(e[i].v);
		vec[e[i].v].push_back(e[i].u);
	}
	ans=0;
	for(int i=1,id;i<=k;i++){
		scanf("%d",&id);
		rt1=e[id].u,rt2=e[id].v;
		dfs(rt1,rt2);
		dfs(rt2,rt1);
		ans=(ans+dp[rt1]*dp[rt2]%M)%M;
	}
	printf("%lld\n",ans);
}
int main(){//24pts
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	jc[0]=1;
	for(int i=1;i<=1e5;i++)jc[i]=jc[i-1]*i%M;
//	solve();
//	return 0;
	cin>>c>>T;
	while(T--){
		solve();
	}
	return 0;
}/*
3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2
*/ 
