#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5, mod = 1e9 + 7, N = 1e5;
int qpow(int x, int k, int p) {
	int res = 1;
	while(k) {
		if(k & 1)
			res = res * x % p;
		k >>= 1, x = x * x % p;
	}
	return res;
}
int c, T, x[maxn], y[maxn], use[maxn], jc[maxn], revjc[maxn], all, res, dp[maxn], out[maxn], f[maxn], n, k;
vector<int> e[maxn], ans[maxn];
unordered_map<int, int> mp[maxn];
void clr() {
	for (int i = 1; i <= n; i++)
		e[i].clear(), ans[i].clear(), mp[i].clear(), use[i] = 0;
}
void dfs1(int u, int fa) {
	f[u] = fa;
	int nw = jc[e[u].size() - 1];
	for (int i = 0; i < e[u].size(); i++) {
		int v = e[u][i];
		if(v == fa)
			continue;
		dfs1(v, u);
		nw = nw * dp[v] % mod;
	}
	dp[u] = nw;
	for (int i = 0; i < e[u].size(); i++) {
		int v = e[u][i];
		if(v == fa)
			continue;
		ans[u][mp[u][v]] = dp[u] * qpow(dp[v], mod - 2, mod) % mod;
	}
}
void dfs2(int u, int fa) {
	for (int i = 0; i < e[u].size(); i++) {
		int v = e[u][i];
		if(v == fa)
			continue;
		out[v] = ans[u][mp[u][v]] * out[u] % mod;
	}
	for (int i = 0; i < e[u].size(); i++) {
		int v = e[u][i];
		if(v == fa)
			continue;
		dfs2(v, u);
	}
}
int dp1[maxn];
void dfs3(int u, int fa) {
	dp1[u] = 0;
	for (int i = 0; i < e[u].size(); i++) {
		int v = e[u][i];
		if(v == fa)
			continue;
		dfs3(v, u);
	}
	int t = jc[(e[u].size() == 1 ? 1 : e[u].size() - 2)];
	int s = 0;
	for (int i = 0; i < e[u].size(); i++) {
		int v = e[u][i];
		if(v == fa)
			continue;
		res -= dp1[v] * s % mod * t % mod * out[u] % mod;
		res = (res + mod) % mod;
		s = s + dp1[v]; s %= mod;
	}
	dp1[u] = s;
	dp1[u] = dp1[u] * t % mod;
	if(use[u]) {
		res -= out[u] * dp1[u] % mod;
		res = (res + mod) % mod; 
		dp1[u] = dp[u];
	}
//	cout << u << " " << dp1[u] << " " << use[u] << endl;
}
void solve() {
	cin >> n >> k;
	clr();
	int s = 0;
	for (int i = 1; i < n; i++) {
		cin >> x[i] >> y[i];
		e[x[i]].push_back(y[i]);
		e[y[i]].push_back(x[i]);
		mp[x[i]][y[i]] = e[x[i]].size() - 1;
		mp[y[i]][x[i]] = e[y[i]].size() - 1;
		ans[x[i]].push_back(0);
		ans[y[i]].push_back(0);
	}
	dfs1(1, 0);
	out[1] = 1;
	dfs2(1, 0);
	for (int p, i = 1; i <= k; i++) {
		cin >> p;
		if(f[x[p]] == y[p])
			use[x[p]] = 1;
		else
			use[y[p]] = 1;
	}
	all = dp[1];
	res = k * all % mod;
	dfs3(1, 0);
	cout << res << endl;
}
void prepare() {
	jc[0] = 1;
	for (int i = 1; i <= N; i++)
		jc[i] = jc[i - 1] * i % mod;
	revjc[0] = revjc[1] = 1;
	for (int i = 2; i <= N; i++)
		revjc[i] = (mod - mod / i) * revjc[mod % i] % mod;
	for (int i = 2; i <= N; i++)
		revjc[i] = revjc[i - 1] * revjc[i] % mod;
}
signed main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	prepare();
	cin >> c >> T;
	while(T--)
		solve();
	return 0;
}
