#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
namespace fastio{
	template<typename T> inline void read(T &t){
		T x = 0, f = 1;
		char c = getchar();
		while(!isdigit(c)){
			if(c == '-') f = -f;
			c = getchar();
		}
		while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
		t = x * f;
	}
	template<typename T, typename ... Args> inline void read(T &t, Args &...args){
		read(t), read(args...);
	}
}
using namespace fastio;
//bool stt[2];
int T, tid;
const ll mod = 1e9 + 7;
void add(ll &x, ll y){x = (x + y) % mod;}
void dec(ll &x, ll y){x = (x - y + mod) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll ksm(ll p, ll h){
	ll base = p, res = 1;
	while(h){
		if(h & 1ll) res = res * base % mod;
		base = base * base % mod, h >>= 1ll;
	}
	return res;
}
ll inv2;
const int N = 2e5 + 5, _ = 2e5 + 1;
int n, m;
bool vis[N], vis2[N];
vector<pii> G[N];
pii e[N];
ll fac[N], ifac[N];
ll f[N], g[N], h[N], sum[N], invf[N];
void dfs1(int u, int fa){
	for(auto &i : G[u]){
		int v = i.fi, w = i.se;
		if(v == fa) continue;
		dfs1(v, u);
		if(vis[w]) vis2[v] = 1;
	}
}
void dfs(int u, int fa){
	f[u] = 1, h[u] = 0; ll tot = 1;
	for(auto &i : G[u]){
		int v = i.fi, w = i.se;
		if(v == fa) continue;
		dfs(v, u), sum[v] += vis[w], sum[u] += sum[v];
		mul(tot, f[v]);
	}
	vector<int> nxt;
	for(auto &i : G[u]) if(i.fi != fa) nxt.pb(i.fi);
	int len = nxt.size();
	f[u] = tot * fac[len] % mod;
	_rep(i, 0, len - 1){
		if(!sum[nxt[i]]) continue;
		int v = nxt[i];
		ll cur = tot * invf[v] % mod * g[v] % mod * fac[len] % mod;
		add(g[u], cur);
		cur = (fac[len] - fac[len - 1] + mod) % mod * tot % mod * invf[v] % mod * h[v] % mod;
		add(g[u], cur);
		cur = tot * invf[v] % mod * h[v] % mod * fac[len - 1] % mod;
		add(h[u], cur);
	}
	if(vis2[u]) h[u] = f[u];
	ll now = 0, lst = 0;
	_rep(i, 0, len - 1){
		int v = nxt[i];
		if(!sum[v]) continue;
		ll cur = invf[nxt[i]] * h[nxt[i]] % mod;
		add(now, cur * lst % mod);
		add(lst, cur);
	}
	if(len > 0) dec(g[u], now * tot % mod * fac[len - 1] % mod);
	invf[u] = ksm(f[u], mod - 2);
}
void solve(){
	read(n, m);
	_rep(i, 1, n - 1){
		int u, v; read(u, v);
		G[u].pb({v, i}), G[v].pb({u, i});
		e[i] = {u, v};
	}
	int rt = 0;
	_rep(i, 1, m){
		int id; read(id), rt = id;
		vis[id] = 1;
	}
	rt = e[rt].fi;
	dfs1(rt, 0);
	dfs(rt, 0);
	vector<int> nxt; for(auto &i : G[rt]) nxt.pb(i.fi);
	int len = nxt.size();
	ll tot = 1;
	for(auto &v : nxt) mul(tot, f[v]);
	ll ans = 0;
	_rep(i, 0, len - 1){
		if(!sum[nxt[i]]) continue;
		int v = nxt[i];
		ll cur = tot * invf[v] % mod * g[v] % mod * fac[len - 1] % mod;
		add(ans, cur);
		cur = fac[len - 1] * tot % mod * invf[v] % mod * h[v] % mod;
		add(ans, cur);
	}
	ll now = 0, lst = 0;
	_rep(i, 0, len - 1){
		int v = nxt[i];
		if(!sum[v]) continue;
		ll cur = invf[nxt[i]] * h[nxt[i]] % mod;
		add(now, cur * lst % mod);
		add(lst, cur);
	}
	if(len > 1) dec(ans, now * tot % mod * fac[len - 2] % mod);
	printf("%lld\n", ans);
}
void clr(){
	_rep(i, 1, n) f[i] = g[i] = h[i] = 0, G[i].clear(), vis[i] = sum[i] = vis2[i] = 0;
}
//bool edd[2];
int main(){
//	debug("use %.3lfMB\n", abs(stt - edd) / 1024.00 / 1024.00);
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	fac[0] = fac[1] = ifac[0] = ifac[1] = 1, inv2 = ksm(2, mod - 2);
	_rep(i, 2, _) fac[i] = fac[i - 1] * i % mod, ifac[i] = (mod - mod / i) * ifac[mod % i] % mod;
	_rep(i, 2, _) ifac[i] = ifac[i - 1] * ifac[i] % mod;
	read(tid, T);
	while(T--){
		solve();
		clr();
	}
	return 0;
}
/*
1 1
4 1
1 2
2 3
2 4
1

2
-----
7 1
5 2
1 2
1 3
2 4
2 5
1 3

3
---
1 1
6 1
1 2
1 5
2 3
2 4
5 6
4

2
*/
