#include <bits/stdc++.h>
using namespace std;

constexpr int MOD = 1000000007;

int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int C, T;
	cin >> C >> T;
	for (int arona = 1; arona <= T; arona++)
	{
		int n, k;
		cin >> n >> k;
		vector<vector<int>> e(n + 1, vector<int>());
		vector<int> s(k + 1);
		for (int i = 1; i < n; i++)
		{
			int u, v;
			cin >> u >> v;
			e[u].push_back(v);
			e[v].push_back(u);
		}
		for (int i = 1; i <= k; i++)
		{
			cin >> s[i];
		}
		if (C == 18)
		{
			cout << "1\n";
			continue;
		}
//		else if (C >= 19 && C <= 21)
		else
		{
			auto quickPow = [&](int a, int b) -> int
			{
				int ans = 1;
				while (b)
				{
					if (b & 1)  ans = 1LL * ans * a % MOD;
					a = 1LL * a * a % MOD;
					b >>= 1;
				}
				return ans;
			};
			int tmp1 = 1, tmp2 = 1, inv2 = quickPow(2, MOD - 2);
			for (int i = 2; i <= n - 1; i++)  tmp1 = 1LL * tmp1 * i % MOD;
			for (int i = 2; i <= n - 3; i++)  tmp2 = 1LL * tmp2 * i % MOD;
			cout << (1LL * tmp1 * inv2 % MOD - 1LL * (n - k - 1) * (n - k - 2) % MOD * tmp2 % MOD * inv2 % MOD + MOD) % MOD << '\n';
			continue;
		}
	}
	return 0;
}

/*
thx for the free 16pts /se
*/
