#include <iostream>
#include <vector>
using namespace std;

#define MAXN 100005
#define MOD 1000000007ll

using ll = long long;

ll qpow(ll b, ll p, ll m)
{
	ll r = 1;
	while (p)
	{
		if (p & 1)
		{
			r = r * b % m;
		}
		b = b * b % m;
		p >>= 1;
	}
	return r;
}

int n, k, m, CCCCC;

struct Edge
{
	int u, v;
} es[MAXN];
vector<int> e[MAXN];

int cs[MAXN];

bool vis[MAXN];

int dep[MAXN], fa[MAXN];

ll fac[MAXN];

ll siz[MAXN], res;

ll calc(ll v, ll n)
{
	if (v == 1 || n == 1)
	{
		return n * fac[v - 1] % MOD;
	}
	return (n * fac[v - 1] % MOD - n * (n - 1) / 2 % MOD * fac[v - 2] % MOD + MOD) % MOD;
}

void dfs(int p, int f)
{
	dep[p] = dep[f] + 1;
	fa[p] = f;
	siz[p] = vis[p];
	int v = e[p].size(), cn = 0;
	for (int u : e[p])
	{
		if (u == f)
		{
			continue;
		}
		dfs(u, p);
		siz[p] += siz[u];
		if (siz[u])
		{
			cn++;
		}
	}
	if (siz[p] != m)
	{
		cn++;
	}
	(res *= calc(v, cn)) %= MOD;
}

int dis[MAXN];

void dfs2(int p)
{
	for (int u : e[p])
	{
		if (dis[u])
		{
			continue;
		}
		if (dis[p] < 0)
		{
			dis[u] = dis[p] - 1;
		}
		else
		{
			dis[u] = dis[p] + 1;
		}
		dfs2(u);
	}
}

void solve1()
{
	ll res = 1;
	for (int i = 1; i <= n; i++)
	{
		(res *= calc(e[i].size(), 1)) %= MOD;
	}
	int i = cs[1];
	dis[es[i].u] = 1, dis[es[i].v] = -1;
	dfs2(es[i].u);
	dfs2(es[i].v);
	int j = cs[2];
	if (abs(dis[es[j].u]) > abs(dis[es[j].v]))
	{
		swap(es[j].u, es[j].v);
	}
	ll nres = res;
	int v = es[j].u;
	int u = es[i].v;
	if (dis[v] > 0)
	{
		u = es[i].u;
		// cout << 1 << ' ';
	}
	while (dep[u] != dep[v])
	{
		if (dep[u] < dep[v])
		{
			swap(u, v);
		}
		(nres *= qpow(e[u].size() - 1, MOD - 2, MOD)) %= MOD;
		u = fa[u];
	}
	while (u != v)
	{
		(nres *= qpow(e[u].size() - 1, MOD - 2, MOD)) %= MOD;
		u = fa[u];
		(nres *= qpow(e[v].size() - 1, MOD - 2, MOD)) %= MOD;
		v = fa[v];
	}
	(nres *= qpow(e[u].size() - 1, MOD - 2, MOD)) %= MOD;
	cout << (2 * res - nres + MOD) % MOD << endl;
}

void solve()
{
	cin >> n >> k;
	m = 0;
	res = 1;
	for (int i = 1; i <= n; i++)
	{
		e[i].clear();
		vis[i] = false;
		dep[i] = 0;
		fa[i] = 0;
		dis[i] = 0;
	}
	for (int i = 1; i < n; i++)
	{
		int u, v;
		cin >> u >> v;
		es[i] = {u, v};
		e[u].push_back(v);
		e[v].push_back(u);
	}
	for (int i = 1; i <= k; i++)
	{
		int c;
		cin >> c;
		cs[i] = c;
		m -= vis[es[c].u] + vis[es[c].v];
		vis[es[c].u] = vis[es[c].v] = 1;
		m += vis[es[c].u] + vis[es[c].v];
	}
	dfs(1, 1);
	if (CCCCC >= 7 && CCCCC <= 10)
	{
		return solve1();
	}
	cout << res << endl;
}

int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> CCCCC >> t;
	fac[0] = 1;
	for (int i = 1; i < MAXN; i++)
	{
		fac[i] = fac[i - 1] * i % MOD;
	}
	while (t--)
	{
		solve();
	}
	return 0;
}

