#include <bits/stdc++.h>
#define ll long long
#define pir pair <ll, ll>
#define mkp make_pair
#define fi first
#define se second
#define pb emplace_back
using namespace std;

void rd(ll &x) {
	char ch; bool f = 0;
	while(!isdigit(ch = getchar()))
		if(ch == '-') f = 1;
	x = ch - '0';
	while(isdigit(ch = getchar()))
		x = (x << 1) + (x << 3) + ch - '0';
	if(f) x = -x;
}

const ll maxn = 1e5 + 10, mod = 1e9 + 7;

ll power(ll a, ll b = mod - 2) {
	ll s = 1;
	while(b) {
		if(b & 1) s = s * a %mod;
		a = a * a %mod, b >>= 1;
	} return s;
}

ll t, n, k, deg[maxn], key[maxn], fac[maxn];
vector <pir> to[maxn]; ll f[maxn], ans, inv[maxn];

void dfs(ll u, ll c = 0, ll fa = 0) {
	for(pir e: to[u])
		if(e.fi ^ fa) {
			ll v = e.fi, p = e.se;
			dfs(v, key[p], u);
			ans = (ans + mod - f[v] * f[u] %mod) %mod;
			f[u] = (f[u] + f[v] * inv[deg[u] - 1]) %mod;
		}
	if(c) ans = (ans + mod - f[u]) %mod, f[u] = 1;
}

void solve() {
	rd(n), rd(k); fac[0] = 1;
	for(ll i = 1; i <= n; i++) fac[i] = fac[i - 1] * i %mod;
	for(ll i = 1; i <= n; i++)
		deg[i] = f[i] = key[i] = 0, to[i].clear();
	for(ll i = 1; i < n; i++) {
		ll u, v; rd(u), rd(v);
		to[u].pb(mkp(v, i)), to[v].pb(mkp(u, i));
		++deg[u], ++deg[v];
	}
	for(ll i = 1, x; i <= k; i++)
		rd(x), key[x] = 1;
	inv[1] = 1;
	for(ll i = 2; i <= n; i++)
		inv[i] = (mod - mod / i) * inv[mod % i] %mod;
	ans = k, dfs(1);
	for(ll i = 1; i <= n; i++) ans = ans * fac[deg[i] - 1] %mod;
	printf("%lld\n", ans);
}

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	rd(t), rd(t); while(t--) solve();
	return 0;
}
