// Lucky_Luo NOIP2024 rp+=inf;
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef double db;
const int N = 1e5 + 7, mo = 1e9 + 7;
int i, j, k, l, r, m, n, idx, cnt, E;
int ans[N], h[N], f[N], t[N], pw[N];
struct Edge
{
	int a, b, c, n;
} d[N<<1], e[N];
int qp(int a, int b=mo-2)
{
	int res = 1;
	for (; b; b>>=1,a=1ll*a*a%mo) if (b&1) res = 1ll * res * a % mo;
	return res;
}
void edge(int a, int b, int c)
{
	d[++E] = {a, b, c, h[a]}, h[a] = E;
	d[++E] = {b, a, c, h[b]}, h[b] = E;
}
void dfs(int a, int fa)
{
	int i, b;
	f[a] = 1, t[a] = 0;
	for (i=h[a]; i; i=d[i].n)
	{
		b = d[i].b;
		if (b != fa) t[a]++, dfs(b, a), f[a] = 1ll * f[a] * f[b] % mo;
	}
	f[a] = 1ll * f[a] * pw[t[a]] % mo;
}
void solve()
{
	scanf("%d %d", &n, &m);
	for (i=1; i<=n; i++) h[i] = 0;
	for (E=0,i=1; i<n; i++)
	{
		scanf("%d %d", &l, &r);
		e[i] = {l, r, i, 0}, edge(l, r, i);
	}
	for (pw[0]=i=1; i<=n; i++) pw[i] = qp(i, i-1);
	int ans = 0;
	for (i=1; i<=m; i++) 
	{
		scanf("%d", &k);
		dfs(e[k].a, e[k].b), dfs(e[k].b, e[k].a);
		int res = 1ll * f[e[k].a] * f[e[k].b] % mo;
		ans = (ans + res) % mo;
	}
	printf("%d\n", ans);
}
signed main()
{
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int T; scanf("%*d %d", &T);
	while (T--) solve();
	return 0;
}

