//NOIP2024 RP++
//不要挂分，不要挂分，不要挂分
//debug 深入思考，只靠样例与自己 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double wisdom;

const int N = 1e5 + 5, mod = 1e9 + 7, i2 = (mod + 1) / 2;
struct Edge {int now, nxt;} e[N << 1]; int head[N], cur;
void add(int u, int v) {e[++cur].now = v, e[cur].nxt = head[u], head[u] = cur;}

namespace K1 {
	int dfs(int u, int fa) {
		int ans = 1;
		for (int i = head[u], v, son = 0; i; i = e[i].nxt) if ((v = e[i].now) != fa) ans = 1ll * ans * (++son) % mod, ans = 1ll * ans * dfs(v, u) % mod;
		return ans;
	}
	void sol() {
		int n, k, ans = 0; scanf("%d%d", &n, &k);
		cur = 0; for (int i = 1; i <= n; i++) head[i] = 0;
		for (int i = 1, u, v; i < n; i++) scanf("%d%d", &u, &v), add(u, v), add(v, u);
		while (k--) {
			int x; scanf("%d", &x); int u = e[2 * x - 1].now, v = e[2 * x].now;
			ans = (ans + 1ll * dfs(u, v) * dfs(v, u)) % mod;
		}
		printf("%d\n", ans);
	}
}
namespace SP {
	void sol() {
		int n, k, fac1 = 1, fac2 = 1; scanf("%d%d", &n, &k);
		for (int i = 1; i <= n - 3; i++) fac1 = 1ll * fac1 * i % mod;
		for (int i = 1; i <= n - 2; i++) fac2 = 1ll * fac2 * i % mod;
		for (int i = 1; i < n; i++) scanf("%*d%*d"); for (int i = 1; i <= k; i++) scanf("%*d");
		printf("%lld\n", (1ll * fac2 * k % mod - 1ll * k * (k - 1) % mod * i2 % mod * fac1 % mod + mod) % mod);
	}
}
int main() {
	freopen("traverse.in", "r", stdin); freopen("traverse.out", "w", stdout);
	int c, T; scanf("%d%d", &c, &T);
	if (c == 18) {while (T--) puts("1");}
	else if (19 <= c && c <= 21) {while (T--) SP::sol();}
	else while (T--) K1::sol();
	return 0;
}
