#include <bits/stdc++.h>
typedef long long LL;
typedef std::pair<int, int> pii;
#define fi first
#define se second
#define MP std::make_pair

char buf[1 << 20], *p1, *p2;
#define gc() ((p1 == p2) && ((p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin)), (p1 == p2)) ? 0 : *p1++)
//#define gc() getchar()
int read()
{
	int s = 0, f = 1; char c = gc();
	for (; !isdigit(c); c = gc()) f ^= (c == '-');
	for (; isdigit(c); c = gc()) s = s * 10 + (c ^ 48);
	return f ? s : -s;
}
template<typename T> 
void write(T x, char end = '\n')
{
	if (x < 0) x = -x, putchar('-');
	static int d[100], cur = 0;
	do { d[++cur] = x % 10; } while (x /= 10);
	while (cur) putchar('0' + d[cur--]);
	putchar(end);
}
template<typename T> 
void Fmax(T &x, T y){ if (x < y) x = y; }
template<typename T> 
void Fmin(T &x, T y){ if (y < x) x = y; }
const int MOD = 1e9 + 7;
int fplus(int x, int y){ return x + y >= MOD ? x + y - MOD : x + y; }
int fminus(int x, int y){ return x >= y ? x - y : x + MOD - y; }
void Fplus(int &x, int y){ x = fplus(x, y); }
void Fminus(int &x, int y){ x = fminus(x, y); }
int fpow(int x, int y = MOD - 2)
{
	int res = 1;
	for (; y; y >>= 1, x = (LL)x * x % MOD)
		if (y & 1) res = (LL)res * x % MOD;
	return res;
}
const int MAXN = 100005;
int Tcnt, Tid;
int n, K, fac[MAXN], key[MAXN], kid[MAXN], inv[MAXN], ifac[MAXN], val[MAXN];
int coef, f[MAXN], g[MAXN];
pii edge[MAXN];
std::vector<pii> e[MAXN];
std::vector<int> fa[MAXN];
void dfs1(int x, int fat)
{
	f[x] = 0;
	for (pii y : e[x])
	{
		if (y.fi == fat) continue;
		dfs1(y.fi, x);
		if (kid[y.se]) Fplus(coef, f[y.fi]), Fplus(f[x], 1);
		else Fplus(f[x], f[y.fi]);
	}
	f[x] = (LL)f[x] * val[x] % MOD;
}
void dfs2(int x, int fat)
{
	static int tmp[MAXN];
	int m = e[x].size();
	for (int i = 0; i < m; i++)
		if (kid[e[x][i].se]) tmp[i] = 1;
		else if (e[x][i].fi == fat) tmp[i] = g[x];
		else tmp[i] = f[e[x][i].fi];
	int sum = 0;
	for (int i = 0; i < m; i++) Fplus(sum, tmp[i]);
	for (int i = 0; i < m; i++)
	{
		pii y = e[x][i];
		if (y.fi == fat) continue;
		g[y.fi] = (LL)(MOD + sum - tmp[i]) * val[x] % MOD;
		if (kid[y.se]) Fplus(coef, g[y.fi]);
	}
	for (pii y : e[x]) if (y.fi != fat) dfs2(y.fi, x);
}
void mian()
{
	n = read(), K = read();
	for (int i = 1; i < n; i++)
	{
		edge[i].fi = read(), edge[i].se = read();
		e[edge[i].fi].emplace_back(edge[i].se, i);
		e[edge[i].se].emplace_back(edge[i].fi, i);
	}
	for (int i = 1; i <= K; i++) 
		kid[key[i] = read()] = i;
	int ans = 1;
	for (int i = 1; i <= n; i++) 
		ans = (LL)ans * fac[(int)e[i].size() - 1] % MOD;
	for (int i = 1; i <= n; i++)
		val[i] = (e[i].size() > 1) ? (LL)ifac[e[i].size() - 1] * fac[e[i].size() - 2] % MOD : 1;
	coef = g[1] = 0, dfs1(1, 0), dfs2(1, 0);
	coef = (LL)coef * inv[2] % MOD;
	ans = (LL)ans * (MOD + K - coef) % MOD;
	write(ans);
}
int main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	fac[0] = ifac[0] = inv[1] = 1;
	for (int i = 2; i <= 100000; i++)
		inv[i] = MOD - (LL)MOD / i * inv[MOD % i] % MOD;
	for (int i = 1; i <= 100000; i++)
	{
		fac[i] = (LL)i * fac[i - 1] % MOD;
		ifac[i] = (LL)inv[i] * ifac[i - 1] % MOD;
	}
	for (Tid = read(), Tcnt = read(); Tcnt--; )
	{
		mian();
		for (int i = 1; i <= n; i++) e[i].clear();
		memset(kid, 0, n << 2);
	}
	return 0; 
}
