#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int n, k, dp[N], fn[N];
int Tc[N];
struct edge {
	int x, y;
}E[N];
long long fast_pow (long long base, int zs) {
	base %= mod;
	int res = 1;
	while (zs) {
		if (zs & 1) res = 1ll * res * base % mod;
		base = 1ll * base * base % mod;
		zs >>= 1;
	}
	return res;
}
vector<int> G[N];
int val[N];
void dfs (int u, int faa) {
//	cout << u << '\n';
	for (int i = 0; i < G[u].size(); i++) {
		int v = G[u][i];
		if (v == faa) continue;
		dfs (v, u);
	}
	dp[u] = 1;
	if (u > n) {
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if (v == faa) continue;
			dp[u] = 1ll * dp[u] * dp[v] % mod;
		}
	} else {
		dp[u] = Tc[G[u].size() - 1];
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if (v == faa) continue;
			dp[u] = 1ll * dp[u] * dp[v] % mod;
		}
		if (dp[u] == 0) dp[u] = 1;
	}
}
void solve () {
	scanf("%d%d", &n, &k);
	for (int i = 1; i < n; i++) 
		scanf("%d%d", &E[i].x, &E[i].y);
	int id = n;
	for (int i = 1; i < n; i++) {
		++id;
		G[E[i].x].push_back(id);
		G[E[i].y].push_back(id);
		G[id].push_back(E[i].x);
		G[id].push_back(E[i].y);
	}
	long long ans = 0;
	for (int i = 1; i <= k; i++) {
		scanf("%d", &fn[i]);
		dfs(fn[i] + n, 0);
		ans += dp[fn[i] + n] % mod;
		ans %= mod;
	}
	cout << (ans + mod) % mod << '\n';
	for (int i = 1; i <= id; i++) G[i].clear(), dp[i] = 0;
}
signed main () {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int c, T;
	scanf("%d%d", &c, &T);
	Tc[1] = 1;
	Tc[0] = 1;
	for (int i = 2; i <= N; i++) Tc[i] = 1ll * Tc[i - 1] * i % mod;
	while (T--) solve();
	return 0;
}
