#include<bits/stdc++.h>
#define eb emplace_back
#define mk(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
const int N=100005,mod=1e9+7;
int fac[N],ifac[N],deg[N];
int ksm(int x,int y){
	int s=1;
	while (y){
		if (y&1)s=1ll*s*x%mod;
		x=1ll*x*x%mod,y>>=1;
	}
	return s;
}
void INIT(int n=N-5){
	fac[0]=1;
	for (int i=1;i<=n;++i)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=ksm(fac[n],mod-2);
	for (int i=n-1;i>=0;--i)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
int ID,T,X[N],Y[N],n,e[N],f[N],m;
bool bz[N],vis[N],bz2[N];
vector<pair<int,int>>v[N];
void dfs(int x){
	f[x]=1;vis[x]=1;
	int son=0;
	bool ck=0;
	for (auto o:v[x]){
		int y=o.fi,z=o.se;
		if (bz[z])continue;
		if (vis[y])continue;
		dfs(y);
		if (bz2[z])ck=1;
		++son;
		f[x]=1ll*f[x]*f[y]%mod;
	}
	if (ck)f[x]=1ll*f[x]*fac[son-1]%mod*(son-1)%mod;
	else 
	f[x]=1ll*f[x]*fac[son]%mod;
}
void solve(){
	cin>>n>>m;
	for (int i=1;i<n;++i){
		cin>>X[i]>>Y[i];
		v[X[i]].eb(mk(Y[i],i));
		v[Y[i]].eb(mk(X[i],i));
		++deg[X[i]];
		++deg[Y[i]];
	}
	for (int i=1;i<=m;++i)cin>>e[i],bz2[e[i]]=1;
	if (ID==18){
		cout<<1<<"\n";
		return;
	}
	if (ID>=19&&ID<=21){
		if (n==2){
			cout<<1<<"\n";
		}
		else if (n==3){
			cout<<1<<"\n";
		}
		else{
			int ans=0,ss=0;
			for (int i=1;i<=m;++i){
				ans=(ans+fac[n-2])%mod;
				ans=(ans+mod-ss)%mod;
				ss=(ss+fac[n-3])%mod;
			}
			cout<<ans<<"\n";
		}
		return;
	}
	int s=0;
	for (int j=1;j<=m;++j){
		if (j==1){
			int ans=1;
			for (int i=1;i<=n;++i){
				int son=deg[i]-1;ans=1ll*ans*fac[son]%mod;
			}
			s=(s+ans)%mod;
		}
		else{
			int ans=1;
			for (int i=1;i<=n;++i){
				int son=deg[i]-1;
				if (son==-1)continue;
				ans=1ll*ans*fac[son]%mod;
			}
			s=(s+ans)%mod;
		}
	}
	cout<<s<<"\n";
//	int s=0;
//	for (int i=1;i<=m;++i){
//		for (int j=1;j<=n;++j)vis[j]=0;
//		bz[e[i]]=1;
////		bz2[e[i]]=0;
//		int ans=1;
//		if (!vis[X[e[i]]]){
//			dfs(X[e[i]]);
//			ans=1ll*ans*f[X[e[i]]]%mod;
//		}
//		if (!vis[Y[e[i]]]){
//			dfs(Y[e[i]]);
//			ans=1ll*ans*f[Y[e[i]]]%mod;
//		}
////		cout<<ans<<"\n";
//		s=(s+ans)%mod;
//		bz[e[i]]=0;
//	}
//	cout<<s<<"\n";
}
void init(){
	for (int i=1;i<=n;++i)v[i].clear(),deg[i]=0,bz[i]=bz2[i]=0,vis[i]=0;
}
int main(){
	freopen("traverse.in","r",stdin);freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>ID>>T;INIT();
	while (T--)solve(),init();
}
