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

int read()
{
	int x = 0;
	char c = getchar();
	while (c < '0' || c > '9')
		c = getchar();
	while (c >= '0' && c <= '9')
		x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return x;
}

const int MAXN = 1e5 + 5;
const int N = 1e5;
const int MOD = 1e9 + 7;

int cnt;
int head[MAXN];

struct edge
{
	int to, nxt;
}e[MAXN << 1];

void Add(int u, int v)
{
	e[++cnt] = edge{v, head[u]};
	head[u] = cnt;
}

int uu[MAXN], vv[MAXN], fac[MAXN];
int q[MAXN], dp[MAXN];

stack<int> stk;
bool flg;
bool vis[MAXN];

void Dfs2(int u, int f, int s)
{
	stk.push(u);
	if (u == s)
	{
		flg = true;
		return;
	}
	for (int i = head[u]; i; i = e[i].nxt)
	{
		int v = e[i].to;
		if (v == f)
			continue;
		Dfs2(v, u, s);
		if (flg)
			return;
	}
	stk.pop();
}

void Dfs(int u, int f)
{
	if (flg)
		vis[u] = true;
	dp[u] = 1;
	int tot = 0;
	for (int i = head[u]; i; i = e[i].nxt)
	{
		int v = e[i].to;
		if (v == f || vis[v])
			continue;
		Dfs(v, u);
		tot++;
		dp[u] = 1ll * dp[u] * dp[v] % MOD;
	}
	dp[u] = 1ll * dp[u] * fac[tot] % MOD;
}

//int dl1, dl2, nw;
//vector<int> mp[MAXN], G[MAXN];
//bool vis[MAXN];

//void Dfs2(int u)
//{
//	mp[nw].push_back(u);
//	vis[u] = true;
//	for (int i = head[u]; i; i = e[i].nxt)
//	{
//		int v = e[i].to;
//		if (vis[v])
//			continue;
//		Dfs2(v);
//	}
//}

void Init()
{
	fac[0] = 1;
	for (int i = 1; i <= N; i++)
		fac[i] = 1ll * fac[i - 1] * i % MOD;
}

void Clear(int n)
{
	cnt = 0;
	memset(head, 0, sizeof(int) * (n + 2));
	memset(vis, false, sizeof(bool) * (n + 2));
//	for (int i = 1; i < n; i++)
//		mp[i].clear(), mp[i].shrink_to_fit(), G[i].clear(), G[i].shrink_to_fit();
}

int main()
{
	freopen("traverse.in", "r", stdin); freopen("traverse.out", "w", stdout);
	Init();
	int c = read(), T = read();
	while (T--)
	{
		int n = read(), k = read();
		Clear(n);
		for (int i = 1; i < n; i++)
		{
			uu[i] = read(); vv[i] = read();
			Add(uu[i], vv[i]); Add(vv[i], uu[i]);
		}
		for (int i = 1; i <= k; i++)
			q[i] = read();
//		assert(k == 1);
		flg = false;
		if (k == 1)
		{
			int u = uu[q[1]], v = vv[q[1]];
			Dfs(u, v); Dfs(v, u);
			printf("%lld\n", 1ll * dp[u] * dp[v] % MOD);
		}
		else if (c == 18)
			puts("1");
		else if (k == 2)
		{
			int ans = 0;
			for (int i = 1; i <= 2; i++)
			{
				int u = uu[q[i]], v = vv[q[i]];
				Dfs(u, v); Dfs(v, u);
				ans = (ans + 1ll * dp[u] * dp[v] % MOD) % MOD;
			}
			Dfs2(uu[q[1]], 0, uu[q[2]]);
			while (!stk.empty())
			{
				vis[stk.top()] = true;
				stk.pop();
			}
			vis[uu[q[1]]] = vis[vv[q[1]]] = vis[uu[q[2]]] = vis[vv[q[2]]] = true;
			memset(dp, 0, sizeof(int) * (n + 2));
			int res = 1;
			for (int i = 1; i <= n; i++)
			{
				if (!vis[i])
				{
					Dfs(i, 0);
					res = 1ll * res * dp[i] % MOD;
				}
			}
			ans = (ans - res + MOD) % MOD;
//			for (int u = 1; u <= n; u++)
//			{
//				for (int i = head[u]; i; i = e[i].nxt)
//				{
//					for (int j = head[u]; j; j = e[j].nxt)
//					{
//						int ii = (i + 1) >> 1, jj = (j + 1) >> 1;
//						if (ii >= jj)
//							continue;
//						G[ii].push_back(jj), G[jj].push_back(ii);
//					}
//				}
//			}
//			dl1 = q[1], dl2 = q[2];
//			vis[dl1] = vis[dl2] = true;
//			for (int i = 1; i < n; i++)
//				if (!vis[i])
//					nw++, Dfs2(i);
//			for (int i = 1; i <= nw; i++)
//			{
//				for (unsigned j = 0; j < mp[nw].size(); j++)
//				{
//					for (unsigned k = j + 1; k < mp[nw].size(); k++)
//					{
//						if (G[j])
//					}
//				}
//			}
			printf("%d\n", ans);
		}
	}
	return 0;
}
