#include<bits/stdc++.h>
#define N 100007
#define mod 1000000007
#define ll long long

using namespace std;

inline int read(){
	int ret=0;char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') ret=(ret<<3)+(ret<<1)+c-'0',c=getchar();
	return ret;
}

ll qpow(ll k,int x){
	ll ret=1;
	for(;x;k=k*k%mod,x>>=1) if(x&1) ret=ret*k%mod;
	return ret;
}

int n,m,flg[N],siz[N];
ll f[N][2],fac[N];
vector<pair<int,int> > G[N];

void dfs(int u,int fa,int x){
	siz[u]=0,f[u][1]=0,f[u][0]=1;
	int cnt=0;
	for(auto p:G[u]){
		int v=p.first,id=p.second;
		if(v==fa) continue;
		dfs(v,u,id),siz[u]+=siz[v]+flg[id];
		(f[u][0]*=f[v][0])%=mod;
		if(siz[v]+flg[id]) cnt++;
	}
	if(x&&flg[x]) (f[u][1]+=f[u][0]*fac[G[u].size()-1])%=mod;
	for(auto p:G[u]){
		int v=p.first,id=p.second;
		if(v==fa) continue;
		(f[u][1]+=f[u][0]*qpow(f[v][0],mod-2)%mod*f[v][1]%mod*fac[G[u].size()-1])%=mod;
	}
	(f[u][0]*=fac[G[u].size()-1])%=mod;
}

void mian(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) G[i].clear();
	bool flg1=1,flg2=1;
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		flg1&=(u==i&&v==i+1),flg2&=(u==1&&v==i+1);
		G[u].push_back({v,i}),G[v].push_back({u,i});
	}
	memset(flg,0,sizeof(flg));
	for(int i=1,x;i<=m;i++) x=read(),flg[x]=1;
	if(flg1) return puts("1"),void();
	if(flg2){
		ll ans=(1ll*m*fac[n-2]-1ll*m*(m-1)/2%mod*fac[n-3])%mod;
		return printf("%lld\n",ans<0?ans+mod:ans),void();
	}
	dfs(1,0,0);
	printf("%lld\n",f[1][1]<0?f[1][1]+mod:f[1][1]);
}

int main()
{
	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%mod;
	int _,T;scanf("%d%d",&_,&T);
	while(T--) mian();
	return 0;
}
