# include <bits/stdc++.h>
# define pb push_back
# define int long long
using namespace std;

const int mod = 1e9 + 7, N = 1e5 + 5;

int ksm(int x, int p){
	int ret = 1;
	while (p){
		if (p & 1) ret = ret * x % mod;
		x = x * x % mod;
		p >>= 1;
	}
	return ret;
}

int n, k, f[N], sz[N], fa[N], uu[N], v[N], dep[N], q[N], fac[N], vis[N], inv[N], h[N], ind[N];

vector <int> g[N];

void dfs(int u){
//	vis[u]++;
//	printf("%lld ", u);
	sz[u] = 0; dep[u] = dep[fa[u]] + 1; f[u] = 1;
	for (int v : g[u]) if (v != fa[u]) sz[u]++;
	if (h[u] == 0) h[u] = 1;
	for (int v : g[u]) if (v != fa[u]){
		if (sz[u] == 1) h[v] = h[u];
		else h[v] = h[u] * inv[sz[u]] % mod * (fac[sz[u]-1] * (sz[u]-1) % mod) % mod;
	}
	for (int v : g[u]) if (v != fa[u]){
		fa[v] = u, dfs(v), (f[u] *= f[v]) %= mod;
//		 sz[u]++;
	}
	(f[u] *= fac[sz[u]]) %= mod;
//	printf("%lld %lld\n", u, f[u]);
//	int U = fa[u];
//	if (sz[U] == 0){
//		h[u] = 1;
//		return ;
//	}
//	if (U == v[q[1]] || U == uu[q[1]]){
//		h[u] = inv[sz[U]] % mod * fac[sz[U]-1] % mod + (sz[U] >= 2 ? (sz[U]-2) * fac[sz[U]-1] % mod : 0);
//	}
//	else{
//		h[u] = h[fa[u]] * inv[sz[U]] % mod * fac[sz[U]-1] % mod + (sz[U] >= 2 ? (sz[U]-2) * fac[sz[U]-1] % mod : 0);
//	}
}

void solve(int T){
	scanf("%lld%lld", &n, &k);
	for (int i = 0;i <= n;i++) f[i] = sz[i] = fa[i] = uu[i] = v[i] = dep[i] = q[i] = vis[i] = h[i] = ind[i] = 0, g[i].clear();
	for (int i = 1;i < n;i++){
		scanf("%lld%lld", &uu[i], &v[i]);
		g[uu[i]].pb(v[i]); g[v[i]].pb(uu[i]);
		ind[uu[i]]++; ind[v[i]]++;
	}
	for (int i = 1;i <= k;i++) scanf("%lld", &q[i]);
//	int res = 0;
//	for (int i = 1;i <= n;i++) if (ind[i] == 1) res = i;
//	fa[res] = g[res][0];
//	dfs(res);
//	int ans = f[res];
//	fa[g[res][0]] = res; dfs(g[res][0]);
	sort (q+1, q+k+1);
	int m = unique (q+1, q+k+1) - q - 1;
	fa[uu[q[1]]] = v[q[1]]; dfs(uu[q[1]]);
	fa[v[q[1]]] = uu[q[1]]; dfs(v[q[1]]);
	int ans = f[uu[q[1]]] * f[v[q[1]]] % mod;
//	int ans = f[res] * f[g[res][0]] % mod;
//	g[0].pb(1);
//	fa[0] = -1;
//	dfs(0);
//	int ans = f[1];
	if (m == 1){
		printf("%lld\n", ans);
		return ;
	}
	int tmp = ans; 
//	ans = 0;
	for (int i = 2;i <= m;i++){
		int U = uu[q[i]], V = v[q[i]];
		if (dep[U] > dep[V]) swap(U, V);
//		if (sz[U] <= 1) continue;
//		if (T == 8) 
		
//		printf("$%lld %lld %lld %lld$\n", sz[U], dep[U], dep[V], h[V]);
		int num = (tmp * inv[sz[U]] % mod * fac[sz[U]-1] % mod + (sz[U] >= 2 ? (sz[U]-2) * fac[sz[U]-1] % mod : 0)) % mod;
		num = (num * inv[sz[1]] % mod * fac[sz[1]-1] % mod + (sz[1] >= 2 ? (sz[1]-2) * fac[sz[1]-1] % mod : 0)) % mod;
		num = tmp * h[V] % mod;
		(ans += num) %= mod;
	}
//	printf("%lld %lld\n", tmp, ans);
	printf("%lld\n", ans);
}

signed main(){
	freopen("traverse.in",  "r", stdin);
	freopen("traverse.out", "w", stdout);
//	freopen("traverse1.in", "r", stdin);
	fac[1] = fac[0] = inv[0] = 1;
	for (int i = 2;i <= 100001;i++) fac[i] = fac[i-1] * i % mod;
	for (int i = 1;i <= 100001;i++) inv[i] = inv[i-1] * ksm(i, mod-2) % mod;
	int c, T; scanf("%lld%lld", &c, &T);
	for (int o = 1;o <= T;o++) solve(o);
	return 0;
}

/*
1 1
4 1
1 2
2 3
2 4
1

*/

