#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int M=100005;
const ll mod=1e9+7;
int c,T,n,k,u[M],v[M],h[M];
int to[M<<1],nxt[M<<1],tot;
int res;char ch;
inline int read(){
	res=0;ch=getchar();
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		res=(res<<3)+(res<<1)+(ch&15);
		ch=getchar();
	}
	return res;
}
void add_edge(int u,int v){
	to[++tot]=v;
	nxt[tot]=h[u];
	h[u]=tot;
}
int h2[M],to2[M<<1],nxt2[M<<1],tot2;
void add_edge2(int u,int v){
	to2[++tot2]=v;
	nxt2[tot2]=h2[u];
	h2[u]=tot2;
}
void dfs(int x,int fa,int fe){
	for(int i=h[x];i;i=nxt[i]){
		if(to[i]==fa) continue;
		dfs(to[i],x,i);
		add_edge2(fe>>1,i>>1);
		add_edge2(i>>1,fe>>1);
	}
}
int soncnt[M],e;ll dp[M],mul[M];
ll ans,dp2[M],dp3[M],f[M];
ll qpow(ll x,ll y=mod-2){
	ll res=1;
	while(y){
		if(y&1) res=res*x%mod;
		y>>=1;x=x*x%mod; 
	}
	return res;
}
ll Mul;
void dfs2(int x,int fa){
	dp[x]=1;soncnt[x]=0;
	for(int i=h2[x];i;i=nxt2[i]){
		if(to2[i]==fa) continue;
		++soncnt[x];
		dfs2(to2[i],x);
		Mul=Mul*dp[to2[i]]%mod;
		dp[x]=dp[x]*dp[to2[i]]%mod;
	}
	mul[x]=dp[x];
	if(soncnt[x]) dp[x]=dp[x]*soncnt[x]%mod*f[soncnt[x]]%mod;
}
bool mk[M];
void dfs3(int x,int fa){
	if(mk[x]){
		ans+=dp3[x];
		if(ans>=mod) ans-=mod;
	}
	for(int i=h2[x];i;i=nxt2[i]){
		if(to2[i]==fa) continue;
		if(x){
			dp2[to2[i]]=1;
			if(soncnt[x]!=1)
				dp2[to2[i]]=dp2[to2[i]]*mul[x]*qpow(dp[to2[i]])%mod*f[soncnt[x]-1]%mod*(soncnt[x]-1)%mod;
			if(fa) dp2[to2[i]]=dp2[to2[i]]*dp2[fa]%mod;
			dp3[to2[i]]=dp2[to2[i]]*dp[to2[i]]%mod;
			if(soncnt[to2[i]]) dp3[to2[i]]=dp3[to2[i]]*2%mod;
			dfs3(to2[i],x);
		}
		else{
			dp2[to2[i]]=dp3[to2[i]]=1;
			if(soncnt[to2[i]]) dp3[to2[i]]=mul[to2[i]]*f[soncnt[to2[i]]]%mod*soncnt[to2[i]]%mod;
			if(soncnt[0]!=1) dp3[to2[i]]=dp3[to2[i]]*f[soncnt[0]-1]%mod*(soncnt[0]-1)%mod*Mul%mod*qpow(dp[to2[i]])%mod;
			dfs3(to2[i],x);
		}
	}
//	printf("%d %lld %lld %lld\n",x,dp[x],dp2[x],dp3[x]);
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read(),T=read();
	f[0]=f[1]=1;
	for(int i=2;i<=M-5;i++)
		f[i]=qpow(i,i-2);
	while(T--){
		n=read(),k=read();
		tot=tot2=1;
		for(int i=1;i<n;i++){
			u[i]=read(),v[i]=read();
			add_edge(u[i],v[i]);
			add_edge(v[i],u[i]);
		}
		for(int i=1;i<=k;i++){
			e=read();mk[e]=1;
		}
		dfs(1,0,0);
		Mul=1;
		dfs2(0,-1);
		ans=0;
		dfs3(0,-1);
		printf("%lld\n",ans);
		for(int i=1;i<=n;i++)
			h[i]=0;
		for(int i=0;i<n;i++)
			h2[i]=0; 
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
/*
fopen feropen .in","w" .out","r"
*/ 
