#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long fac[100001];
void work() {
	int k, n, o, w;
	scanf("%d%d", &n, &k);
	for (int i = 1; i < n; i++)
		scanf("%d%d", &o, &w);
	for (int i = 1; i <= k; i++)
		scanf("%d", &o);
	long long ans = fac[n];
	if (k == n - 1) {
		printf("%lld\n", ans);
		return;
	}
	long long f = 1;
	for (int i = n - k - 1; i < n - 1; i++)
		f *= 1ll * i, f %= mod;
	printf("%lld\n", ((ans - f * fac[n - k] % 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");
		return 0;
	}
	fac[0] = 1;
	for (int i = 1; i <= 100000; i++)
		fac[i] = fac[i - 1] * 1ll * i % mod;
	while (t--) work();
	return 0;
}
