#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = (a);i <= (b);i++)
#define int long long
using namespace std;
int testcase,cnt;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
int n,k;
int e[N],fac[N],u[N],v[N];
bool visited[N];
vector<int> graph[N];
int dfs(int p)
{
	visited[p] = true;
	//叶子节点
	if (graph[p].size() == 1)
		return 1;
	int ans = fac[graph[p].size() - 1];
	for (auto j : graph[p])
		if (!visited[j])
			ans = ans * dfs(j) % mod;
	return ans;
}
void solve1()
{
	//定义一条边的编号为其子节点编号 
	memset(visited,0,sizeof visited);
	cout << max(dfs(v[e[1]]),dfs(u[e[1]])) << '\n';
}
void solve()
{
	rep1(i,1,n)
		graph[i].clear();
	cnt++;
	cin >> n >> k;
	rep1(i,1,n - 1)
	{
		cin >> u[i] >> v[i];
		graph[u[i]].push_back(v[i]);
		graph[v[i]].push_back(u[i]);
	}
	rep1(i,1,k)
		cin >> e[i];
	//k=1
	if (testcase <= 6)
		solve1();
	else if (testcase == 18)
		cout << "1\n";
}
signed main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int t;
	cin >> testcase >> t;
	//预处理阶乘
	fac[0] = 1;
	rep1(i,1,1e5)
		fac[i] = fac[i - 1] * i % mod;
	while (t--)
		solve();
}

