#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
	ll s=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		s=s*10+(ch-'0');
		ch=getchar();
	}
	return s*f;
}
ll c,T,n,k;
ll head[200010],to[200010],ne[200010],id,fac[200010],vis[200010],in[200010],ans,res,inv[200010],ifac[200010];
ll f[200010][2];
void add(ll u,ll v){
	to[++id]=v,ne[id]=head[u],head[u]=id;
}
const ll mod=1e9+7;
ll power(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod,b>>=1;
	}
	return ans;
}
void dfs(ll u,ll fa){
	if(in[u]==1) f[u][0]=1;
	for(ll i=head[u],v;i;i=ne[i]){
		v=to[i];
		if(v==fa) continue;
		dfs(v,u);
		if(vis[i>>1]) f[v][1]=(f[v][1]+f[v][0])%mod,f[v][0]=0;
		ans=(ans+(f[v][1]+f[v][0])%mod*(f[u][1]+f[u][0])%mod*inv[in[u]-1]%mod)%mod;
		ans=(ans+mod-(f[v][0])%mod*(f[u][0])%mod*inv[in[u]-1]%mod)%mod;
		f[u][0]=(f[u][0]+f[v][0])%mod,f[u][1]=(f[u][1]+f[v][1])%mod;
	}
	f[u][0]=f[u][0]*inv[in[u]-1]%mod;
	f[u][1]=f[u][1]*inv[in[u]-1]%mod;
//	printf("%lld %lld %lld\n",u,f[u][0],f[u][1]);
//	printf("%lld\n",ans*res%mod);
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read(),T=read();
	while(T--){
		n=read(),k=read();
		id=fac[0]=inv[0]=1;
		for(ll i=1;i<=n;i++) head[i]=0,fac[i]=fac[i-1]*i%mod,vis[i]=in[i]=0,f[i][0]=f[i][1]=0;
		ifac[n]=power(fac[n],mod-2);
		for(ll i=n;i>=1;i--) ifac[i-1]=ifac[i]*i%mod,inv[i]=ifac[i]*fac[i-1]%mod;
		for(ll i=1,u,v;i<n;i++)
			u=read(),v=read(),add(u,v),add(v,u),in[u]++,in[v]++;
		for(ll i=1;i<=k;i++) vis[read()]=1;
		ans=0,res=1;
		for(ll i=1;i<=n;i++) res=res*fac[in[i]-1]%mod;
		dfs(1,0);
		ans=ans*res%mod;
		printf("%lld\n",ans);
	}
	return 0;
}
