#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5;
const ll P=1e9+7;
int ID,n,k,u[N+5],v[N+5],fa[N+5],es[N+5],siz[N+5],f[N+5];
vector<int> e[N+5];
ll ans,fac[N+5];;
void dfs0(int u){
	for(int v:e[u]) if(v!=fa[u])
		fa[v]=u,dfs0(v);
}
void dfs1(int u){
	f[u]=0;
	for(int v:e[u]) if(v!=fa[u]){
		dfs1(v);
		siz[u]+=siz[v]+es[v];
		if(siz[v]+es[v]) ++f[u];
	}
}
void dfs2(int u){
	for(int v:e[u]) if(v!=fa[u]){
		if(siz[1]-siz[v]) ++f[v];
		dfs2(v);
	}
	int E=e[u].size();
	ll sum=f[u]*fac[E-1]%P;
	if(f[u]>1) sum+=P-1ll*f[u]*(f[u]-1)/2%P*fac[E-2]%P;
	ans=ans*sum%P;
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=1;
	for(int i=1;i<=N;++i) fac[i]=fac[i-1]*i%P;
	int T;cin>>ID>>T;
	if(ID==18){
		while(T--) cout<<"1\n";
		return 0;
	}
	while(T--){
		cin>>n>>k;
		if(n==1){
			cout<<"1\n";
			continue;
		}
		for(int i=1;i<n;++i){
			cin>>u[i]>>v[i];
			e[u[i]].push_back(v[i]);
			e[v[i]].push_back(u[i]); 
		}
		dfs0(1);
		for(int i=1,x;i<=k;++i){
			cin>>x;
			if(fa[u[x]]==v[x]) swap(u[x],v[x]);
			es[v[x]]=1;
		}
		ans=1,dfs1(1),dfs2(1);
		cout<<ans<<'\n';
		for(int i=1;i<=n;++i) e[i].clear(),es[i]=siz[i]=0;
	}
}
