#include <bits/stdc++.h>
using namespace std;
const int N = 100240, M = N << 1, P = 1000000007;
int h[N], nxt[M], to[M], tt;
inline void AE(int x, int y)
{
	nxt[++tt] = h[x], to[h[x] = tt] = y;
}
int CCF;
int f[N];
inline void Init(int n = 100000)
{
	f[0] = f[1] = 1;
	for (int i = 2; i <= n; ++i)
	{
		f[i] = 1ll * f[i - 1] * i % P;
	}
}
inline void Solve()
{
	int n, k;
	cin >> n >> k;
	fill(h + 1, h + n + 1, 0);
	for (int i = 1; i < n; ++i)
	{
		int x, y;
		cin >> x >> y;
		AE(x, y);
		AE(y, x);
	}
	if (CCF == 18)
	{
		while (k-- != 0)
		{
			int e;
			cin >> e;
		}
		cout << "1\n";
	}
	else if (19 <= CCF && CCF <= 21)
	{
		int s = 0;
		for (int i = 1; i <= k; ++i)
		{
			int e;
			cin >> e;
			s = ((s + f[n - 2]) % P - (i == 1 ? 0 : 1ll * f[n - 3] * (i - 1)) % P + P) % P;
		}
		cout << s << '\n';
	}
	else
		cout << "1\n";
}
int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Init();
	int t;
	cin >> CCF >> t;
	while (t-- != 0)
		Solve();
	return 0;
}
