// Code by Heratino & Nelofus
// No I still can't seem to
// Sing more than blues when It's time for my verse
// It's true that I need you
// To turn my blues into bursting fireworks
#include <bits/stdc++.h>
using i64 = long long;

constexpr int N = 1e5 + 10;
constexpr int mod = 1e9 + 7;
inline int Add(const int &x, const int &y) {return x + y >= mod ? x + y - mod : x + y;}
inline int Sub(const int &x, const int &y) {return x - y < 0 ? x - y + mod : x - y;}
inline int Mul(const int &x, const int &y) {return 1ll * x * y % mod;}
inline void AddTo(int &x, const int &y) {x = Add(x, y);}
inline void SubTo(int &x, const int &y) {x = Sub(x, y);}
inline void MulTo(int &x, const int &y) {x = Mul(x, y);}
inline int fpow(int x, int k) {
	int res = 1;
	for (; k; k >>= 1, MulTo(x, x))
		if (k & 1)
			MulTo(res, x);
	return res;
}

int fac[N], ifac[N];
std::pair<int, int> edg[N];
std::vector<int> nu;
std::vector<int> G[N];

int ans = 1;
void dfs(int u, int fa) {
	int deg = 0;
	for (const int &v : G[u]) {
		if (v == fa)
			continue;
		dfs(v, u);
		deg++;
	}
	MulTo(ans, fac[deg]);
}
inline void solve(int type) {
	int n, k;
	std::cin >> n >> k;
	for (int i = 1; i <= n; i++)
		G[i].clear();
	nu.resize(k);
	for (int i = 1; i < n; i++) {
		int u, v;
		std::cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
		edg[i] = std::make_pair(u, v);
	}
	for (int i = 0; i < k; i++) {
		std::cin >> nu[i];
	}
	if (type == 18) {
		std::cout << "1" << '\n';
		return ;
	} else if (type >= 19 && type <= 21) {
		int res = Mul(k, fac[n - 2]);
		SubTo(res, Mul(n - 3 >= 0 ? fac[n - 3] : 0, Mul(k, Mul(k - 1, fpow(2, mod - 2)))));
		std::cout << res << '\n';
		return ;
	} else if (type <= 6) {
		ans = 1;
		int u = edg[nu[0]].first;
		int v = edg[nu[0]].second;
		dfs(u, v);
		dfs(v, u);
		std::cout << ans << '\n';
	}
}
int main() {
#ifdef HeratinoNelofus
	freopen("input.txt", "r", stdin);
#else
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
#endif
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = Mul(fac[i - 1], i);
	ifac[N - 1] = fpow(fac[N - 1], mod - 2);
	for (int i = N - 2; i >= 0; i--)
		ifac[i] = Mul(ifac[i + 1], i + 1);
	int c, T;
	std::cin >> c >> T;
	while (T--) {
		solve(c);
	}
	return 0;
}
