#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define fi first
#define se second
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
	return x;
}
const int N=1e5+3;
const int mod=1e9+7;
inline void Ad(int &x,int y){x=x+y>=mod?x+y-mod:x+y;}
inline void Mi(int &x,int y){x=x<y?x-y+mod:x-y;}
typedef pair<int,int> pii;
int n,fac[N];
bool vis[N];
vector<pii>G[N];
int f[N][3];
inline void init(){
	rep(i,1,n){
		vis[i]=0,G[i].clear();
	}
}
int ans;
inline void dfs(int u,int fa){
	for(pii A:G[u])if(A.fi!=fa)dfs(A.fi,u);
	static int a[N],b[N];int m=0;
	for(pii A:G[u])if(A.fi!=fa)a[++m]=A.fi,b[m]=vis[A.se];
	if(m==0){
		f[u][0]=1;
		return ;
	}
	if(m==1&&u==1){
		int v=a[1];
		if(b[1])ans=f[v][2];
		else {
			ans=0;
			rep(p,0,2)Ad(ans,f[v][p]);
		}
		return ;
	}
	int c[3]={1,0,0};
	rep(i,1,m){
		int d[3]={0,0,0},v=a[i];
		rep(p,0,2){
			Ad(d[p],1ll*c[p]*f[v][1]%mod);
			Ad(d[p],1ll*c[p]*f[v][0]%mod);
		}
		rep(p,0,1){
			Ad(d[p+1],1ll*c[p]*f[v][2]%mod);
			if(!b[i])Ad(d[p+1],1ll*c[p]*(f[v][0]+f[v][1])%mod);
		}
		rep(p,0,2)c[p]=d[p];
	}
	if(u==1){
		ans=1ll*c[2]*fac[m-2]%mod;
	}
	else{
		f[u][2]=1ll*c[2]*fac[m-1]%mod;
		f[u][1]=1ll*c[1]*fac[m-1]%mod;
	}
}
inline void solve(){
	init();
	n=read();int Q=read();
	rep(i,1,n-1){
		int u=read(),v=read();
		G[u].pb(P(v,i)),G[v].pb(P(u,i));
	}
	if(Q==1){
		read();
		int res=1;
		rep(i,1,n)res=1ll*res*fac[G[i].size()-1]%mod;
		printf("%d\n",res);
		return ;
	}
	memset(f,0,sizeof f);
	dfs(1,0);
	int ans1=ans;
	while(Q--)vis[read()]=1;
	memset(f,0,sizeof f);
	dfs(1,0);
	int ans2=ans;
	Mi(ans1,ans2);
	printf("%d\n",ans1);
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	read();int T=read();
	fac[0]=1;rep(i,1,N-1)fac[i]=1ll*fac[i-1]*i%mod;
	while(T--)solve();
	return 0;
}
