#include <bits/stdc++.h>
#define fst first
#define snd second
using namespace std;
using ll = long long;
using ld = long double;

const long long IMX = 1ll << 30;
const long long LMX = 1ll << 60;
const int N = 100005, MOD = 1000000007;
struct Edge { int to, id; };
ll id, T, n, k, ans = 1;
ll s[N], lvl[N], fac[N], invf[N];
bool vis[N];
vector <Edge> G[N];
ll qpow(ll n, ll m, ll p) {
	ll res = 1;
	while (m) {
		if (m & 1) res = res % p * n % p;
		n = n % p * n % p, m >>= 1;
	}
	return res;
}
ll C(ll n, ll m, ll p) {
	if (n < 0 or m < 0 or n < m) return 0;
	return fac[n] * invf[n - m] % p * invf[m] % p;
}
void dfs(int cur, int p, int pid) {
	lvl[cur] = lvl[p] + 1;
	for (auto v : G[cur]) {
		if (v.to == p) continue;
		dfs(v.to, cur, v.id);
	}
	int k = G[cur].size() - 1;
	if (lvl[cur] > 1 and k) {
		int cnt = 0;
		for (int i = 0; i < G[cur].size(); i++) {
			if (G[cur][i].to == p) continue;
			if (vis[G[cur][i].id]) cnt++;
		}
		if (!cnt) ans = ans * k % MOD * fac[k - 1] % MOD;
		else ans = ans * C(k * (k + 1) / 2, k, MOD) % MOD;
	}
}
int main() {
	ios :: sync_with_stdio(0);
	cin.tie(nullptr);
	freopen("D:\\down\\day0\\traverse\\traverse5.in", "r", stdin);
//	freopen("traverse.out", "w", stdout);
	cin >> id >> T;
	fac[0] = 1;
	for (int i = 1; i <= N - 5; i++) fac[i] = fac[i - 1] * i % MOD;
	invf[N - 5] = qpow(fac[N - 5], MOD - 2, MOD);
	for (int i = N - 6; i >= 0; i--) invf[i] = invf[i + 1] * (i + 1) % MOD;
	while (T--) {
		ans = 1;
		cin >> n >> k;
		for (int i = 1; i <= n; i++) G[i].clear(), vis[i] = 0;
		for (int i = 1; i < n; i++) {
			int u, v;
			cin >> u >> v;
			G[u].push_back({v, i});
			G[v].push_back({u, i});
		}
		for (int i = 1; i <= k; i++) {
			int s;
			cin >> s;
			vis[s] = 1;
		}
		dfs(1, 0, 0);
		cout << ans << '\n';
	}
	return 0;
}

