#include <cstdio>
#include <vector>

namespace Main {

using namespace std;

typedef long long LL;

LL read() {
	LL res, f = 1, c;
	for (c = getchar(); (c < '0' || c > '9') && c != '-';)
		c = getchar();
	if (c == '-') {
		f = -1;
		c = getchar();
	}
	for (res = 0; '0' <= c && c <= '9'; c = getchar())
		res = res * 10 + (c & 15);
	return res * f;
}

constexpr bool T = 1;
constexpr int N = 100005, MOD = 1e9 + 7;

int a[N][2], b[N];
vector<int> e[N], vc[N];
LL fac[N], ans;

void dfs(int x, int fa, int op) {
	if (op)
		ans = ans * fac[e[x].size() - 1] % MOD;
	for (int i : e[x])
		if (i != fa)
			dfs(i, x, 1);
	return;
}

void solve(int cid) {
	LL n = read(), m = read();
	for (int i = 1; i <= n; ++i)
		e[i].clear();
	for (int i = 1; i < n; ++i) {
		int u = read(), v = read();
		a[i][0] = u;
		a[i][1] = v;
		e[u].emplace_back(v);
		e[v].emplace_back(u);
	}
	for (int i = 1; i <= m; ++i)
		b[i] = read();
	if (cid == 18) {
		puts("1");
		return;
	}
	if (19 <= cid && cid <= 21) {
		--n;
		if (n == 1) {
			puts("1");
			return;
		}
		m = n - m;
		LL ans = (n * (n - 1) / 2 - m * (m - 1) / 2) % MOD;
		for (int i = n - 2; i; --i)
			ans = ans * i % MOD;
		printf("%lld\n", ans);
		return;
	}
	for (int i = fac[0] = 1; i <= n; ++i)
		fac[i] = fac[i - 1] * i % MOD;

	int x = a[b[1]][0], y = a[b[1]][1];
	ans = fac[e[x].size() + e[y].size() - 2];
	dfs(x, y, 0);
	dfs(y, x, 0);
	printf("%lld\n", ans);
	return;
}

void main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int c = read();
	for (int t = T ? read() : 1; t; --t)
		solve(c);
	return;
}
}

int main() {
	Main::main();
	return 0;
}

