#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
const long long mod=1e9+7;
int cid,T,n,k,e[N+5];
long long ans=0,jc[N+5];
struct edge{
	int x,y;
}w[N+5];
vector<int>G[N+5];
int rd(){
	int t=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9'){
		t=t*10+ch-'0';
		ch=getchar();
	}
	return t;
}
void init(){
	jc[0]=1;
	for(int i=1;i<=N;i++) jc[i]=jc[i-1]*i%mod;
}
void dfs(int u,int fa){
	for(int v:G[u]){
		if(v==fa) continue;
		dfs(v,u);
	}
	ans=ans*jc[(int)G[u].size()-1]%mod;
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	init();
	cid=rd();T=rd();
	while(T--){
		n=rd();k=rd();
		for(int i=1;i<=n;i++) G[i].clear();
		for(int i=1,x,y;i<n;i++){
			x=rd();y=rd();
			G[x].push_back(y);
			G[y].push_back(x);
			w[i]=(edge){x,y};
		}
		for(int i=1;i<=k;i++){
			e[i]=rd();
		}
		if(k==1){
			ans=1;
			dfs(w[e[1]].x,0);
			printf("%lld\n",ans);
			continue;
		}
		if(cid==18){
			printf("1\n");
			continue;
		}
		if(cid>=19&&cid<=21){
			if(n==2){
				printf("1\n");
				continue;
			}
			ans=0;
			for(int i=1;i<=k;i++){
				ans=(ans+jc[n-2]-jc[n-3]*(i-1)%mod+mod)%mod;
			}
			printf("%lld\n",ans);
			continue;
		}
		ans=1;
		dfs(1,0);
		ans=k*ans%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
