#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
const int mod=1e9+7;

int oc,T,n,k;
ll f[maxn],sz[maxn];
int ban[maxn],imp[maxn];
struct node { int u,v; }e[maxn];
int hd[maxn],num_edge=1;
struct EDGE { int nt,v; }edge[maxn*2];
void addedge(int u,int v) {
	edge[++num_edge]={hd[u],v};
	hd[u]=num_edge;
}

void init() {
	for(int i=1;i<=n;i++) hd[i]=f[i]=sz[i]=0;
	num_edge=1;
	for(int i=1;i<=n*2+3;i++) ban[i]=0;
}
void dfs(int u,int fa) {
	f[u]=1;
	for(int i=hd[u];i;i=edge[i].nt) {
		int v=edge[i].v;
		if(v==fa||ban[i]) continue;
		dfs(v,u);
		sz[u]++;
		f[u]=f[u]*f[v]%mod;
	}
	if(sz[u])f[u]=sz[u]*(sz[u]-1)/2%mod*f[u];
}
void subtask1() {
//	cout<<"OK"<<endl;
	ban[imp[1]*2]=ban[imp[1]*2+1]=1;
	int U=e[imp[1]].u,V=e[imp[1]].v;
	dfs(U,0); dfs(V,0);
//	cout<<f[U]<<" "<<f[V]<<endl;
	if(!f[U]) { f[U]=1; printf("%lld\n",1ll*f[U]*f[V]); }
	else if(!f[V]) { f[V]=1; printf("%lld\n",1ll*f[U]*f[V]); }
	else { printf("%lld\n",2ll*f[U]*f[V]%mod);  }
	init();
}
void solve() {
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++) {
		scanf("%d%d",&e[i].u,&e[i].v);
		addedge(e[i].u,e[i].v);
		addedge(e[i].v,e[i].u);
	}
	for(int i=1;i<=k;i++) scanf("%d",&imp[i]);
	if(k==1) subtask1();
}
int main() {
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&oc,&T);
	while(T--) solve();
	return 0;
}
