#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
int Case, T, n, k, d[100005];
bool flag[100005];
LL f[100005], g[100005], h[100005], fac[100005];
LL Pow(LL a, LL b) {
	a = a % MOD;
	LL s = 1;
	while (b) {
		if (b & 1)
			s = s * a % MOD;
		a = a * a % MOD, b = b >> 1;
	}
	return s;
}
struct node { int u, v; } a[100005];
struct Edge { int next, to, id; } E[200005];
int Ecnt, last[100005];
void addedge(int u, int v, int id) { Ecnt++, E[Ecnt].next = last[u], last[u] = Ecnt, E[Ecnt].to = v, E[Ecnt].id = id; }
int num[100005];
void dfs(int x, int fa) {
	int bz = num[x];
	LL ds = 1;
	int son = 0;
	f[x] = g[x] = h[x] = 0;
	for (int xy = last[x]; xy; xy = E[xy].next)
		if (E[xy].to != fa) {
			num[E[xy].to] = flag[E[xy].id], son++;
			dfs(E[xy].to, x);
			ds = ds * (f[E[xy].to] + h[E[xy].to]) % MOD;
		}
	if (!fa) {
		for (int xy = last[x]; xy; xy = E[xy].next)
			g[x] = (g[x] + ds * Pow(f[E[xy].to] + h[E[xy].to], MOD - 2) % MOD * (g[E[xy].to] + h[E[xy].to]) % MOD * fac[d[x] - 1]) % MOD;
		return ;
	}
	if (!son)
		f[x] = 1;
	else
		for (int xy = last[x]; xy; xy = E[xy].next)
			if (E[xy].to != fa) {
				g[x] = (g[x] + ds * Pow(f[E[xy].to] + h[E[xy].to], MOD - 2) % MOD * g[E[xy].to] % MOD * fac[d[x] - 2]) % MOD;
				g[x] = (g[x] + ds * Pow(f[E[xy].to] + h[E[xy].to], MOD - 2) % MOD * (h[E[xy].to] + g[E[xy].to]) % MOD * fac[d[x] - 2] % MOD * (d[x] - 2)) % MOD;
				h[x] = (h[x] + ds * Pow(f[E[xy].to] + h[E[xy].to], MOD - 2) % MOD * h[E[xy].to] % MOD * fac[d[x] - 2]) % MOD;
				f[x] = (f[x] + ds * Pow(f[E[xy].to] + h[E[xy].to], MOD - 2) % MOD * f[E[xy].to] % MOD * fac[d[x] - 2]) % MOD;
			}
	if (bz) {
		h[x] = h[x] + f[x];
		f[x] = 0;
	}
}
void clear() {
	for (int i = 1; i <= n; i++)
		d[i] = last[i] = num[i] = 0, flag[i] = false;
	Ecnt = 0;
}
int main() {
//	freopen("traverse3.in", "r", stdin);
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	scanf("%d%d", &Case, &T);
	while (T--) {
		scanf("%d%d", &n, &k), fac[0] = 1;
		for (int i = 1; i <= n; i++)
			fac[i] = fac[i - 1] * i % MOD;
		for (int i = 1; i < n; i++) {
			scanf("%d%d", &a[i].u, &a[i].v), addedge(a[i].u, a[i].v, i), addedge(a[i].v, a[i].u, i);
			d[a[i].u]++, d[a[i].v]++;
		}
		for (int i = 1, id; i <= k; i++)
			scanf("%d", &id), flag[id] = true;
		dfs(1, 0);
//		printf("f : ");
//		for (int i = 1; i <= n; i++)
//			printf("%lld ", f[i]);
//		printf("\n");
//		printf("g : ");
//		for (int i = 1; i <= n; i++)
//			printf("%lld ", g[i]);
//		printf("\n");
//		printf("h : ");
//		for (int i = 1; i <= n; i++)
//			printf("%lld ", h[i]);
//		printf("\n");
		printf("%lld\n", g[1]);
		clear();
	}
	return 0;
}
