#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100010
ll ans;
const ll p = 1e9 + 7;
int n, k;
struct Edge {
	int u, v;
} e[N];
ll ksm(ll base, ll power) {
	ll res = 1;
	for (; power; base = base * base % p, power >>= 1)
		if (power & 1) res = res * base % p;
	return res;
}
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");
		return 0;
	}
	if (19 <= _c && _c <= 21) {
		
		while (_T--) {
			scanf("%d %d", &n, &k);
			for (int i = 1; i < n; ++i) {
				int u, v;
				scanf("%d %d", &u, &v);
				e[i] = { u, v };
			}
			int xx;
			while (k--) scanf("%d", &xx);
			ans = 1;
			ll x = n - 1;
			x = x * (x - 1) / 2;
			for (ll i = n - 2; i; --i) {
				ans = ans * x % p * ksm(i, p - 2) % p;
				--x;
			//	cout<< i << " " << ans << " " << x << endl;
			}
			ans %= p;
			ll _ans = ans;
			printf("%lld\n", _ans % p);
		}
		return 0;
	}
	while (_T--) {
	//	init();
		puts("1");
	}
	return 0;
} 
