#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5,mod=1e9+7;
struct Edge{
	int v,next;
}e[N<<1];
int head[N],idx;
void add(int u,int v){
	e[++idx]={v,head[u]};
	head[u]=idx;
}
int op,t,n,m,U[N],V[N],f[N],g[N],h[N],dep[N],sz[N],jc[N],rd[N];
bool flag[N];
int fpow(int a,int n){
	int ans=1;
	while(n){
		if(n&1) ans=ans*a%mod;
		a=a*a%mod,n>>=1;
	}
	return ans;
}
void dfs(int u,int fa){
	dep[u]=dep[fa]+1,sz[u]=fa!=0;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].v;
		if(v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
	}
}
void dfs_(int u,int fa){
	f[u]=1;
	int x=0,y=1,z=0;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].v;
		if(v==fa) continue;
		dfs_(v,u);
		f[u]=f[u]*f[v]%mod;
		x=(x+g[v])%mod;
		g[u]=(g[u]+g[v])%mod;
		y=(y+h[v])%mod;
		z=(z+h[v]*fpow(f[v],mod-2))%mod;
	}
	if(sz[u]==1){
		if(flag[u]) g[u]=1;
		else h[u]=1;
		return;
	}
	f[u]=f[u]*jc[sz[u]-2]%mod;
	for(int i=head[u];i;i=e[i].next){
		int v=e[i].v;
		if(v==fa) continue;
		int zz=(z-h[v]*fpow(f[v],mod-2))%mod*fpow(f[v],mod-2)%mod*f[u]%mod;
		g[u]=(g[u]+g[v]*zz)%mod;
	}
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&op,&t);
	while(t--){
		scanf("%lld%lld",&n,&m);
		if(n==2){
			int x;for(int i=1;i<=(n-1)*2+m;i++) scanf("%lld",&x);
			printf("1\n");
			continue;
		}
		memset(head,0,sizeof(head));
		memset(rd,0,sizeof(rd));
		idx=0;
		jc[0]=1;
		for(int i=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;
		for(int i=1;i<n;i++){
			scanf("%lld%lld",&U[i],&V[i]);
			add(U[i],V[i]),add(V[i],U[i]);
			rd[U[i]]++,rd[V[i]]++;
		}
		int root=0;
		for(int i=1;i<=n;i++)
			if(rd[i]>1){
				root=i;
				break;
			}
		dfs(root,0);
		for(int i=1;i<=m;i++){
			int x;scanf("%lld",&x);
			if(dep[U[x]]>dep[V[x]]) flag[U[x]]=1;
			else flag[V[x]]=1;
		}
		dfs_(root,0);
		printf("%lld\n",g[root]);
	}
	
	return 0;
}
