#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5,mod=1e9+7;
int n,k,cnt,h[N],z[N],a[N][2],dp[N];
struct Edge{
	int to,nxt;
}e[N*2];
void add_edge(int u,int v){
	e[++cnt].to=v;
	e[cnt].nxt=h[u];
	h[u]=cnt;
}
void dfs(int x,int fa){
	int siz=0;dp[x]=1;
	for (int i=h[x];i!=-1;i=e[i].nxt){
		int v=e[i].to;if (v==fa) continue ;
		dp[x]=dp[x]*dp[v]%mod;siz++;
	}if (siz) dp[x]=dp[x]*siz%mod;
}
void work(){
	memset(h,-1,sizeof(h));cnt=0;
	memset(dp,0,sizeof(dp));
	cin>>n>>k;
	for (int i=1;i<n;i++){
		int u,v;cin>>u>>v;add_edge(u,v);add_edge(v,u);a[i][0]=u;a[i][1]=v;
	}
	for (int i=1;i<=k;i++) cin>>z[i];
	dfs(a[z[1]][0],a[z[1]][1]);
	dfs(a[z[1]][1],a[z[1]][0]);
	cout<<dp[a[z[1]][0]]*dp[a[z[1]][1]]<<endl;
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0);
	int t,c;cin>>c>>t;while (t--) work();
	return 0;
}
