#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+5,mod=1e9+7;
pii edge[N];
ll f[N];
int k,n;
vector <pii> e[N];
void dfs(int k,int u){
	f[k]=1;
	int cnt=0;
	for(auto t:e[u]){
		int v=t.first,nxtk=t.second;
		if(nxtk!=k){
			dfs(nxtk,v);
			//(f[k]*=f[nxtk])%=mod;
			++cnt;
		} 
	}
	for(int i=1;i<=cnt;++i)
		(f[k]*=cnt)%=mod;
}
void solve(){
	memset(e,0,sizeof(e));
	memset(f,0,sizeof(f));
	cin>>n>>k;
	for(int i=1;i<n;++i){
		int u,v;
		cin>>u>>v;
		e[u].push_back({v,i});
		e[v].push_back({u,i});
		edge[i]={u,v};
	}
	int id;
	for(int i=1;i<=k;++i){
		cin>>id;
	}
	if(k==1){
		dfs(id,edge[k].first);
		dfs(id,edge[k].second);
		cout<<f[k]<<'\n';
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int c,T;
	cin>>c>>T;
	while(T--)
		solve();
	return 0;
}



