#include <bits/stdc++.h>
using namespace std;
const int MAXn = 100010;
const int MAXE = MAXn << 1;
const int MOD = 1e9 + 7;
using l64 = long long;
int tot, to[MAXE], nxt[MAXE], head[MAXn];
l64 fac[MAXn];
void edgadd(int u, int v) {
	to[++tot] = v;
	nxt[tot] = head[u];
	head[u] = tot;
}
int e[MAXn];
int main(void) {
#ifndef DEB_MAC
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
#endif
	int c, T;
	scanf("%d%d", &c, &T);
	//make fulllllll use of c.
	while(T--) {
		int n, k;
		scanf("%d%d", &n, &k);
		tot = 0;
		memset(head, 0, sizeof(int) * (n + 5));
		fac[0] = 1;
		for (int i = 1; i < n; ++i) {
			int u, v;
			scanf("%d%d", &u, &v);
			edgadd(u, v);
			edgadd(v, u);
			fac[i] = fac[i - 1] * 1ll * i % MOD;
		}
		for (int i = 1; i <= k; ++i) {
			scanf("%d", &e[i]);
		}
		if(c == 18) {
			printf("1\n");
			continue;
		}
		if (c == 19 || c == 20 || c == 21) {
			l64 ans = 0;
			//n - 1 = E
			//n - 2 = E - 1
			for (int i = 1; i <= k; ++i) {
				(ans += fac[n - 2]) %= MOD;
			}
			(ans *= 500000004ll) %= MOD;
			printf("%lld", ans);
		}
	}
	return 0;
}
