#include <bits/stdc++.h>
#define _rep(i_, a_, b_) for(int i_ = a_; i_ <= b_; ++i_)
int in(void) { 
	int x = 0, c = getchar();
	while(!isdigit(c)) c = getchar();
	while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
	return x;
}
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int kN = 105000, p = 1000000007;
int fpm(int a, int b) {
	int r = 1;
	for(;b;b >>= 1, a = 1ll * a * a % p) if(b & 1) r = 1ll * r * a % p;
	return r;
}
int n;
vector<pair<int,int>> g[kN];
int vis[kN], f[kN][3], fac[kN];
void dfs(int u, int fa, int eid) {
	vector<int> son, inv;
	for(auto &e : g[u]) {
		int v = e.first, w = e.second;	
		if(v != fa) dfs(v, u, w), son.emplace_back(v);
	}
	int N = son.size();
	if(!N && fa) { f[u][vis[eid]] = 1; return; }
	if(!fa) return;
	int MUL = 1;
	for(auto &v : son) {
		int c = (f[v][0] + f[v][1]) % p;
		MUL = 1ll * MUL * c % p;
		inv.push_back(fpm(f[v][0] + f[v][1], p - 2));
	}
	int ptr = 0;
	for(auto &v : son) {
		int tmp[2] = {};
		int mu = 1ll * MUL * inv[ptr++] % p;
		tmp[0] = 1ll * fac[N - 1] * mu % p * f[v][0] % p;
		tmp[1] = 1ll * fac[N - 1] * mu % p * f[v][1] % p;
		f[u][0] = (f[u][0] + tmp[0]) % p;
		f[u][vis[eid]] = (f[u][vis[eid]] + tmp[1]) % p;
	}
	if(N >= 2) {
		int sum = 0, s0 = 0, s1 = 0; ptr = 0;
		for(auto &v : son) {
			int I = inv[ptr++];	
			s0 = (s0 + 1ll * MUL * I % p * f[v][0]) % p, 
			s1 = (s1 + 1ll * MUL * I % p * f[v][1]) % p;
		} ptr = 0;
		for(auto &v : son) {
			int I = inv[ptr++];
			int a0 = 1ll * MUL * I % p * f[v][0] % p, 
				a1 = 1ll * MUL * I % p * f[v][1] % p;
			a0 = (s0 - a0 + p) % p, a1 = (s1 - a1 + p) % p;
			a0 = 1ll * a0 * I % p, 
			a1 = 1ll * a1 * I % p;
			sum = (sum + 1ll * f[v][0] * (a0 + a1) % p) % p;
			sum = (sum + 1ll * f[v][1] * a0) % p;
		}
		sum = 1ll * sum * fac[N - 1] % p; sum = 1ll * sum * ((p + 1) / 2) % p;
		f[u][2] = (f[u][2] + sum) % p;
	}
	ptr = 0;
	for(auto &v : son) {
		int mu = 1ll * MUL * inv[ptr++] % p;
		f[u][2] = (f[u][2] + 1ll * mu * fac[N] % p * f[v][2]) % p;
	} 
}
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	fac[0] = 1; _rep(i,1,100000) fac[i] = 1ll * fac[i - 1] * i % p;
	in(); int TC = in();
	while(TC--) {
		n = in(); int k = in();	
		_rep(i,1,n - 1) {
			vis[i] = 1;
			int u = in(), v = in();
			g[u].emplace_back(v, i);
			g[v].emplace_back(u, i);
		}
		int rt = 0;
		_rep(i,1,n) if(g[i].size() == 1) { rt = i; }
		while(k--) vis[in()] = 0;
		dfs(rt, 0, 0); 
		int u = g[rt][0].first;
		printf("%d\n", (f[u][0] + f[u][2]) % p);
		_rep(i,1,n) g[i].clear(), f[i][0] = f[i][1] = f[i][2] = 0;
	} 
	return 0;
}

