#include<bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define vc vector
#define vci vc<int>
#define psb push_back
using namespace std;
ll md;
inline ll ksm(ll a, ll b, ll md){
	ll ans = 1;
	while(b){
		if(b & 1) ans = ans * a % md;
		a = a * a % md;
		b >>= 1;
	}
	return ans;
}
inline ll read(){
	ll ans = 0;
	bool fl = 0;
	char c;
	while(1){
		c = getchar();
		if(c == '-' || ('0' <= c && c <= '9')) break;
	}
	if(c == '-') fl = 1;
	else ans = (int)(c - '0');
	while(1){
		c = getchar();
		if(c < '0' || c > '9') break;
		ans = (ans << 3) + (ans << 1);
		ans += (int)(c - '0');
	}
	if(fl) ans = ans * -1;
	return ans;
}
ll jc[1000005], ans, tny, ny[1000005];
int n, k, t, c, hv[1000005], m, cn[1000005], sz[1000005];
int to[1000005], nx[1000005], hd[1000005], tot;
int st[1000005], tp, hx[1000005], f[1000005], cur[1000005];
void add(int a, int b){
	to[tot] = b, nx[tot] = hd[a], hd[a] = tot++;
	sz[a]++;
	to[tot] = a, nx[tot] = hd[b], hd[b] = tot++;
	sz[b]++;
}
//void dfs(int u, int ft){
////	cout << u << endl;
//	for(int i = hd[u]; ~i; i = nx[i]){
//		int v = to[i];
//		if(v == ft) continue;
//		dfs(v, u);
//		if(hv[v]) cn[u]++;
//		hv[u] += hv[v];
//	}
//	if(hv[u] != k) cn[u]++;
//}
void get(){
	m = tp = 0;
	for(int i = 1; i <= n * 2; i++) st[i] = f[i] = hx[i] = 0, cur[i] = hd[i];
	for(int i = 1; i <= n; i++)
		if(sz[i] == 1){
			st[++tp] = i;
			break;
		}
	while(tp){
		int u = st[tp];
		if(cur[u] == -1){
			tp--;
			hx[++m] = u;
			continue;
		}
		int v = to[cur[u]];
		cur[u] = nx[cur[u]];
		if(v != f[u]){
			f[v] = u;
			st[++tp] = v;
		}
	}
}
ll A(int a, int b){
	return jc[a] * ny[a - b] % md;
}
int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	md = 1e9 + 7;
	jc[0] = ny[0] = 1;
	for(int i = 1; i <= 200000; i++) jc[i] = jc[i - 1] * i % md, ny[i] = ny[i - 1] * ksm(i, md - 2, md) % md;
	tny = ksm(2, md - 2, md);
//	cout << ksm(2, 10, md) << endl;
//	cjc[0] = cjc[1] = cjc[2] = 1;
//	for(int i = 3; i <= 1000000; i++) cjc[i] = cjc[i - 1] * i % md;
	cin >> c >> t;
	while(t--){
		cin >> n >> k;
		for(int i = 1; i <= n * 2 + 10; i++) cn[i] = hv[i] = sz[i] = 0, hd[i] = -1;
		ans = 1;
		tot = 0;
		for(int i = 1, a, b; i < n; i++){
			a = read(), b = read();
			add(a, i + n);
			add(b, i + n);
		}
		for(int i = 1, a; i <= k; i++){
			a = read();
			hv[a + n] = 1;
		}
//		for(int i = 1; i <= n; i++)
//			if(sz[i] == 1){
//				dfs(i, 0);
//				break;
//			}
//		for(int i = 1; i <= n; i++) cout << cn[i] << ' ';
//		cout << endl;
		get();
		for(int i = 1; i <= m; i++){
			int u = hx[i];
			int ft = f[u];
			for(int j = hd[u]; ~j; j = nx[j]){
				int v = to[j];
				if(v == ft) continue;
				if(hv[v]) cn[u]++;
				hv[u] += hv[v];
			}
			if(hv[u] != k) cn[u]++;
		}
		for(int i = 1; i <= n; i++){
			if(cn[i] <= sz[i] - 2){
				ans = ans * ((jc[sz[i]] - A(sz[i] - 2, cn[i]) * jc[sz[i] - cn[i]] % md) % md + md) % md * tny % md;
//				cout << "!!";
			}
			else{
				ans = ans * jc[sz[i]] % md;
				if(sz[i] > 1) ans = ans * tny % md;
//				cout << "!";
			}
//			cout << ans << endl;
//			if(cn[i] == 1) ans = ans * jc[sz[i] - 1] % md;
//			else{
//				ans = ans * jc[sz[i]] % md;
//				if(sz[i] > 1) ans = ans * tny % md;
////				cout << "!";
//			}
		}
		cout << ans % md << endl;
	}
	return 0;
}
