#include<bits/stdc++.h>
#define LL long long
#define Maxn 100005
#define Myn 100000
using namespace std;
int rd(){
	int x=0; char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)){ x=x*10+c-48; c=getchar(); }
	return x;
}
const int md = 1000000007;
LL ksm(LL x, LL y){
	LL z=1;
	while(y){
		if(y&1) z=z*x%md;
		x=x*x%md; y>>=1;
	}
	return z;
}

LL fac[Maxn],finv[Maxn];
void pre(){
	fac[0] = 1;
	for(int i=1; i<=Myn; i++) fac[i] = fac[i-1] * i % md;
	finv[Myn] = ksm(fac[Myn], md-2);
	for(int i=Myn; i>=1; i--) finv[i-1] = finv[i] * i % md;
}
LL C(int x, int y){
	return fac[x] * finv[y] % md * finv[x-y] % md;
}

int n,m,rt;
LL ans,all;
vector<int> e[Maxn];
int ex[Maxn],ey[Maxn],d[Maxn];

int fa[Maxn],hav[Maxn],cnt[Maxn];
void dfs1(int x){
	for(int y : e[x])if(y != fa[x]){
		fa[y] = x;
		dfs1(y);
	}
}

void dfs2(int x){
	LL res = all * finv[d[fa[x]]-1] % md;
	if(hav[x]){
		if(d[fa[x]] > 2){
			(ans += fac[d[fa[x]]-2] * (d[fa[x]]-2) % md * res) %= md;
		}
	}
	for(int y : e[x])if(y != fa[x]){
		dfs2(y);
	}
	if(cnt[x] > 1){
		(ans -= fac[d[x]-2] * C(cnt[x], 2) % md * res) %= md;
	}
}

void slv(){
	n=rd(); m=rd();
	for(int i=1; i<=n; i++){
		e[i].clear(); d[i] = 0;
		fa[i] = hav[i] = cnt[i] = 0;
	}
	for(int i=1,x,y; i<n; i++){
		x=rd(); y=rd();
		e[x].emplace_back(y); d[x]++;
		e[y].emplace_back(x); d[y]++;
		ex[i] = x; ey[i] = y;
	}
	
	all = 1;
	for(int i=1; i<=n; i++){
		(all *= fac[d[i]-1]) %= md;
	}
	ans = all;
	
	rt=rd();
	fa[ex[rt]] = ey[rt];
	fa[ey[rt]] = ex[rt];
	dfs1(ex[rt]);
	dfs1(ey[rt]);
	
	for(int i=1,x; i<m; i++){
		x=rd();
		if(fa[ex[x]] == ey[x]){
			hav[ex[x]] = 1;
			cnt[ey[x]]++;
		} else {
			hav[ey[x]] = 1;
			cnt[ex[x]]++;
		}
	}
	
	dfs2(ex[rt]);
	dfs2(ey[rt]);
	
	printf("%lld\n", (ans + md) % md);
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	pre();
	rd(); int ttt=rd();
	while(ttt--) slv();
	return 0;
}

