#include <bits/stdc++.h>
using namespace std;

const int MXN = 1e5 + 1;
const int MOD = 1e9 + 7;

int c, t, n, k, u[MXN], v[MXN], e[MXN];
vector< int > g[MXN];
bool ok1, ok2;
long long mul[MXN], f[MXN];

int read(){
	int x = 0;
	char c = getchar();
	for(;c < '0' || c > '9';) c = getchar();
	for(;c >= '0' && c <= '9';c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x;
}

void dfs(int u, int fa){
	f[u] = 1;
	int cnt = 0;
	for(auto v : g[u])
		if(v != fa){
			dfs(v, u);
			++cnt;
			(f[u] *= f[v]) %= MOD;
		}
	(f[u] *= mul[cnt]) %= MOD;
}

int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout); 
	int i;
	mul[0] = 1;
	for(i = 1;i < MXN;++i) mul[i] = mul[i - 1] * i % MOD;
	for(c = read(), t = read();t;--t){
		n = read();
		k = read();
		for(i = 1;i <= n;++i) g[i].clear();
		ok1 = ok2 = 1;
		for(i = 1;i < n;++i){
			u[i] = read();
			v[i] = read();
			g[u[i]].push_back(v[i]);
			g[v[i]].push_back(u[i]);
			if(u[i] != i || v[i] != i + 1) ok1 = 0;
			if(u[i] != 1 || v[i] != i + 1) ok2 = 0;
		}
		for(i = 1;i <= k;++i) e[i] = read();
		if(ok1) puts("1");
		else if(ok2)
			if(n >= 3) printf("%lld\n", ((long long)k * (k - 1) / 2 % MOD + (long long)k * (n - k - 1) % MOD) * mul[n - 3] % MOD);
			else puts("1");
		else{
			dfs(u[e[1]], v[e[1]]);
			dfs(v[e[1]], u[e[1]]);
			printf("%lld\n", f[u[e[1]]] * f[v[e[1]]] % MOD);
		}
	}
	return 0;
}
