#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define MP make_pair
#define int long long
#define eb emplace_back
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
typedef long long ll;
using namespace std;

int read(){
	int s=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')f^=(c=='-'),c=getchar();
	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
	return f?s:-s;
}

const int N=100005,mod=1e9+7,inv2=(mod+1)/2;
int C,n,k,fa[N],dp[N],fac[N],pw[N],id[N],ans[N],deg[N],sz[N];
vector<int>e[N];
void init(int u,int fat){
	fa[u]=fat;
	sz[u]=id[u];
	for(int v:e[u]){
		if(v==fat)continue;
		init(v,u);
		sz[u]|=sz[v];
	}
}
void dfs1(int u,int fat){
	sz[u]=id[u];
	for(int v:e[u]){
		if(v==fat)continue;
		dfs1(v,u);
		sz[u]|=sz[v];
	}
}
pii edge[N];
void dfs(int u,int fat){
	int flag=0;
	dp[u]=2;
	for(int v:e[u]){
		if(v==fat)continue;
		flag|=sz[v];
		dfs(v,u);
		dp[u]=dp[u]*dp[v]%mod*inv2%mod;
	}
//	if(id[u])printf("(%d %d %d %d)\n",u,fat,flg,flag);
	int cnt=deg[u]-bool(fat);
	if(flag){
		if(fat){
			int now=0;
			now=(now+dp[u]*fac[cnt])%mod;
			for(int v:e[u]){
				if(v==fat)continue;
				if(sz[v]){
					now=(now+dp[u]*fac[cnt])%mod;
				}
			}
			dp[u]=now;
		}else{
			if(cnt==1);
			else dp[u]=dp[u]*fac[cnt-1]%mod;
		}
	}else{
		dp[u]=dp[u]*fac[cnt]%mod;
	}
//	printf("dp[%d]=%d\n",u,dp[u]);
}
int q[N];

signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
//	freopen("traverse3.in","r",stdin);
	C=read();
	fac[0]=pw[0]=1;
	rep(i,1,100000){
		fac[i]=fac[i-1]*i%mod;
		pw[i]=pw[i-1]*2%mod;
	}
	int now=0;
	for(int T=read();T--;){
		n=read(),k=read();
		rep(i,1,n)e[i].clear(),id[i]=0,deg[i]=0;
		rep(i,1,n-1){
			int u=read(),v=read();
			e[u].eb(v),e[v].eb(u);
			deg[u]++,deg[v]++;
			edge[i]=MP(u,v);
		}
		rep(i,1,k)q[i]=read();
		if(k>1){
			int res=1;
			rep(i,1,k)res=res+(fac[k-1]*(k-i))%mod;
			printf("%d\n",res);
			continue;
		}
		int rt=edge[q[1]].fi;
		init(rt,0);
		rep(i,1,k){
			int x=q[i];
			int u=edge[x].fi,v=edge[x].se;
			if(fa[u]==v)id[u]=1;
			else id[v]=1;
		}
		dfs1(rt,0);
		dfs(rt,0);
		printf("%d\n",dp[rt]*inv2%mod);
	}
	return 0;
}

