#include <bits/stdc++.h>
#define int long long
//#define USE_FREOPEN
#define MUL_TEST
#define FILENAME "traverse"
using namespace std;
int c;
int fac[100005],key[100005];
vector<pair<int,int> > G[100005];
vector<int> GE[100005];
int u[100005],v[100005];

int read()
{
	int res = 0,f = 1;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-') f = -1;
		c = getchar();
	}
	while (isdigit(c))
	{
		res = (res << 1) + (res << 3) + (c ^ 48);
		c = getchar();
	}
	return res * f;
}

void dfs(int x,int e,int fa)
{
//	printf("%lld %lld %lld\n",x,e,fa);
	int l = G[x].size();
	for (int i = 0; i < l; i++)
		if (G[x][i].second != fa && G[x][i].second != e)
		{
			GE[e].push_back(G[x][i].second);
			GE[G[x][i].second].push_back(e);
			dfs(G[x][i].first,G[x][i].second,e);
		}
}

void debug(int e,int fa)
{
//	printf("%lld\n",e);
	int l = GE[e].size();
	for (int i = 0; i < l; i++)
		if (GE[e][i] != fa)
			debug(GE[e][i],e);
}

void solve()
{
//	printf("%lld\n",c);
	int n,k;
	n = read();k = read();
	for (int i = 1; i < n; i++)
	{
		u[i] = read();v[i] = read();
		G[u[i]].push_back(make_pair(v[i],i));
		G[v[i]].push_back(make_pair(u[i],i));
	}
	for (int i = 1; i <= k; i++)
	{
		int k;
		k = read();
		key[i] = k;
	}
	if (c == 18)
	{
		puts("1");
		return;
	}
	if (c >= 19 && c <= 21)
	{
		int ans = fac[n - 2];
		int p = 1e9 + 7;
		int minus = (k * (k - 1) / 2) % p;
		minus = minus * fac[n - 3] % p;
		printf("%lld\n",(((ans * k) % p) - minus + p) % p);
		return;
	}
	dfs(G[1][0].first,G[1][0].second,0);
//	debug(G[1][0].second,0);
//	if (k == 1)
//	{
//		dfs
//	}
}

signed main()
{
	#ifdef USE_FREOPEN
		freopen(FILENAME ".in","r",stdin);
		freopen(FILENAME ".out","w",stdout);
	#endif
	cin >> c;
	int _ = 1;
	#ifdef MUL_TEST
		cin >> _;
	#endif
	fac[0] = 1;
	for (int i = 1; i <= 100000; i++)
		fac[i] = fac[i - 1] * i % 1000000007;
	while (_--)
		solve();
	_^=_;
	return (0^_^0);
}

