#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 5e5 + 10, mod = 1e9 + 7;
struct node{
	int x, y;
}ed[N];
int ver[2 * N], nxt[2 * N], head[N], tot;
void add(int x, int y){
	ver[++tot] = y;
	nxt[tot] = head[x];
	head[x] = tot;
}
int n, k;
long long jc[N];
long long f[N], g[N], cnts[N], d[N];
long long qp(long long x, long long y){
	long long res = 1;
	while(y){
		if(y & 1) res = res * x % mod;
		y >>= 1, x = x * x % mod;
	}
	return res;
}
void dfs1(int x, int ff){
	d[x] = d[ff] + 1;
	cnts[x] = 0;
	f[x] = 1;
	for(int i = head[x]; i; i = nxt[i]){
		int y = ver[i];
		if(y == ff) continue;
		cnts[x]++;
		dfs1(y, x);
		f[x] = f[x] * f[y] % mod;
	}
	f[x] = f[x] * jc[cnts[x]] % mod;
}
void dfs2(int x, int ff){
	g[x] = g[ff] * f[ff] % mod * qp(jc[cnts[ff]], mod-2) % mod * qp(f[x], mod - 2) % mod * jc[cnts[ff]] % mod;
	for(int i = head[x]; i; i = nxt[i]){
		int y = ver[i];
		if(y == ff) continue;
		dfs2(y, x);
	}
}
void solve(){
	tot = 0, memset(ver, 0, sizeof(ver));
	memset(head, 0, sizeof(head));
	scanf("%d%d", &n, &k);
	for(int i = 1, u, v; i <= n-1; i++){
		scanf("%d%d", &u, &v);ed[i] = (node){u, v};
		add(u, v), add(v, u);
	}
	dfs1(1, 0);
	dfs2(1, 0);
	long long ans = 0;
	while(k--){
		int e; scanf("%d", &e);
		int x = ed[e].x, y = ed[e].y;
		if(d[ed[e].x] < d[ed[e].y]) swap(x, y);
		ans = (ans + f[x] * g[x] % mod * qp(jc[cnts[y]], mod - 2) % mod * qp(jc[cnts[x]], mod - 2) % mod * jc[cnts[x] + cnts[y]] % mod) % mod;
	}
	printf("%lld\n", ans);
}
int main(){
	jc[0] = 1;
	for(int i = 1; i <= n; i++)
		jc[i] = jc[i-1] * i % mod;
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int c, T; scanf("%d%d", &c, &T);
	while(T--) solve();
	return 0;
}
