#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5, P=1e9+7;
// I don't know how to do it
int c, n, k, p[N], de[N], key[N], fac[N], inv[N];
vector<int> e[N];
vector<int> kn[N];
int u[N], v[N];
int fsp(int a, int b) {
	int c=1;
	for(; b; b>>=1, a=1ll*a*a%P)
		if(b&1) c=1ll*c*a%P;
	return c;
}
void add(int &x, int y) {
	x+=y; x>=P?x-=P:0; 
}
void sub(int &x, int y) {
	x-=y; x<0?x+=P:0;
}
int f[N], ANS=0;
map<pair<int, int>, int> vis;
void Sol() {
	cin>>n>>k;
	int m=n-1;
	for(int i=1; i<n; i++) {
		cin>>u[i]>>v[i];
		e[u[i]].push_back(v[i]);
		e[v[i]].push_back(u[i]);
		de[u[i]+m]++; de[v[i]+m]++;
	}
	
	for(int i=1; i<=k; i++) {
		cin>>p[i];
		int x=u[p[i]], y=v[p[i]];
		key[x+m]++; key[y+m]++;
		vis[{x, y}]=vis[{y, x}]=1;
		kn[x].push_back(y);
		kn[y].push_back(x);
	}
	if(c==18) {
		printf("1\n");
	} else if(c==19) {
		if(k==1) {
			printf("%d\n", fac[m-1]);
		} else {
			printf("%lld\n", 1ll*fac[m-2]*(1ll*(m)*(m-1)/2%P-1ll*(m-k)*(m-k-1)/2%P+P)%P);
		}
	} else if(k==1) {
		int ans=1;
		for(int i=m+1; i<=m+n; i++) {
			ans=1ll*ans*fac[de[i]-1]%P;
		}
		printf("%d\n", ans);
	} else {
		printf("%d\n", 3);
	}
	for(int i=1; i<=n+m; i++) de[i]=0, key[i]=0, e[i].clear(), kn[i].clear();
}
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out","w",stdout);
	for(int i=fac[0]=1; i<N; i++) 	
		fac[i]=1ll*fac[i-1]*i%P;
	inv[N-1]=fsp(fac[N-1], P-2);
	for(int i=N-2; i>=0; i--)
		inv[i]=1ll*inv[i+1]*(i+1)%P;
	cin.tie(0)->sync_with_stdio(false);
	int T;
	cin>>c>>T;
	while(T--) Sol();
	return 0;
}
