#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
int c, t, n, k;
vector<int> e[N];
struct edge{
	int u, v;
}g[N];
int main() {
	
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	scanf("%d%d", &c, &t);
	while(t--) {
		int ke;
		scanf("%d%d", &n, &k);
		for (int i = 1; i < n; i++) {
			int u, v;
			scanf("%d%d", &u, &v);
			e[u].push_back(v);
			e[v].push_back(u);
			g[i].u = u; g[i].v = v;
		}
		for (int i = 1; i <= k; i++) {
			scanf("%d", &ke);
		}
		if (c == 18) printf("1\n");
		else if (c >= 19 && c <= 21) {
			long long ans = k;
			for (int i = 2; i <= 2 * n - 3; i++) {
				ans *= i;
				ans %= mod;
			}
			printf("%lld\n", ans);
		}
	}
	
	return 0;
}
/*
	//freopen("assign.in", "r", stdin);
	//freopen("assign.out", "w", stdout);
*/
