#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define MP make_pair
using namespace std;

const int N = 1e5 + 7, MOD = 1e9 + 7;

int fpow(int x, int y) {
	int ans = 1;
	for (; y; x = x * x  % MOD, y >>= 1)
		if (y & 1) ans = ans * x % MOD;
	return ans;
}

bool flg;
vector<int> e[N];
int n, k, fac[N], u[N], v[N], deg[N], num[N];

void sub1() {
	cin >> n >> k;
	memset(deg, 0, sizeof deg);
	for (int i = 1; i <= n; i ++) e[i].clear();
	for (int i = 1; i < n; i ++) {
		cin >> u[i] >> v[i];
		e[u[i]].push_back(v[i]);
		e[v[i]].push_back(u[i]);
		deg[u[i]] ++, deg[v[i]] ++;
	}
	for (int i = 1; i <= k; i ++) cin >> num[i];
	int mult = 1;
	for (int i = 1; i <= n; i ++)
		mult = mult * fac[deg[i] - 1] % MOD;
	if (k == 1) cout << mult << '\n';
}
void sub2() { cout << 1 << '\n'; }
void sub3() {
	cin >> n >> k;
	for (int i = 1; i < n; i ++) cin >> u[i] >> v[i];
	for (int i = 1; i <= k; i ++) cin >> num[i];
	if (n >= 3) cout << (k * fac[n - 2] % MOD - k * (k - 1) / 2 % MOD * fac[n - 3] % MOD + MOD) % MOD << '\n'; 
	else cout << "1\n";
}

signed main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0); 
	int id, tt;
	cin >> id >> tt;
	fac[0] = 1;
	for (int i = 1; i <= 100000; i ++)
		fac[i] = fac[i - 1] * i % MOD;
	while (tt --) {
		if (id <= 6) sub1();
		else if (id == 18) sub2();
		else if (19 <= id && id <= 21) sub3();
	}
	return 0;
}
 
