#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cassert>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inv2 = (mod + 1) / 2;

int fpow(int a, int b, int p) {
	if (b == 0)
		return 1;
	int ans = fpow(a, b / 2, p);
	ans = 1ll * ans * ans % p;
	if (b % 2 == 1)
		ans = 1ll * ans * a % p;
	return ans;
}
int mmi(int a, int p) {
	return fpow(a, p - 2, p);
}

int fac[N] = {0}, inv[N] = {0}, pw[N] = {0};
void init(int n) {
	pw[0] = 1;
	for (int i = 1; i <= n; i++)
		pw[i] = 2ll * pw[i - 1] % mod;
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = 1ll * i * fac[i - 1] % mod;
	inv[n] = mmi(fac[n], mod);
	for (int i = n - 1; i >= 0; i--)
		inv[i] = 1ll * (i + 1) * inv[i + 1] % mod; 
}


int n, k, ID;
struct Edge {
	int to, idx;
	Edge (int _to = 0, int _idx = 0) :
		to(_to), idx(_idx) {}
};
vector<Edge> e[N];

int id[N] = {0};
int g[N] = {0};
int cnt1[N] = {0};//叶子个数 
int cnt2[N] = {0};//非叶子个数 
int mul[N] = {0};
int p[N] = {0};
void dfs(int x, int pr) {
	g[x] = 1, p[x] = pr;
	cnt1[x] = cnt2[x] = 0;
	for (auto i: e[x])
		if (i.to != pr) {
			dfs(i.to, x);
			id[i.idx] = i.to;
			cnt1[x] += ((cnt1[i.to] + cnt2[i.to]) == 0);
			cnt2[x] += ((cnt1[i.to] + cnt2[i.to]) > 0);
			g[x] = 1ll * g[x] * g[i.to] % mod;
		}
	mul[x] = g[x];
	g[x] = 1ll * fac[cnt1[x] + cnt2[x]] % mod * g[x] % mod; 
//	cout << x << " " << cnt1[x] << " " << cnt2[x] << " " << g[x] << " " << mul[x] << endl;
}
/*
int f[N] = {0};

void srh(int x, int pr) {
	int res1 = cnt1[pr] - (cnt1[x] + cnt2[x] == 0) + ((int)e[p[pr]].size() <= 1);
	int res2 = cnt2[pr] - (cnt1[x] + cnt2[x] > 0) + ((int)e[p[pr]].size() > 1);
	int invg = mmi(g[x], mod);
	f[x] = 1ll * mul[pr] * invg % mod * f[pr] % mod;
	f[x] = 1ll * fac[res2] % mod * fpow(res2 + 1, res1, mod) % mod;
	for (auto i: e[x])
		if (i.to != pr)
			srh(i.to, x);
}*/

void read(int &x) {
	x = 0;
	char ch = getchar();
	while (ch > '9' || ch < '0')
		ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0', ch = getchar();
}

namespace SLV1 {
	
	void slv() {
		for (int i = 1, x; i <= k; i++)
			scanf("%d", &x);
		if (n == 2) {
			printf("1\n");
			return;
		}
		int ans = 1ll * k * fac[n - 2] % mod;
		int cmb = 1ll * k * (k - 1) / 2 % mod;
		cmb = 1ll * cmb * fac[n - 3] % mod;
		ans = (ans - cmb % mod + mod) % mod;
		cout << ans << endl;
	} 
}

void slv() {
	read(n), read(k);
	init(n);
	for (int i = 1; i <= n; i++)
		e[i].clear();
	bool flg = true, flg2 = true;
	for (int i = 1, u, v; i < n; i++) {
		read(u), read(v);
		e[u].push_back(Edge(v, i));
		e[v].push_back(Edge(u, i)); 
		flg = flg && (u == i && v == i + 1);
		flg2 = flg2 && (u == 1 && v == i + 1);
	}
	if (flg) {
		for (int i = 1, x; i <= k; i++)
			read(x);
		printf("1\n");
		return;
	}
	if (flg2) {
		SLV1::slv();
		return;
	}
	dfs(1, 0);
//	cout << g[1] << endl;
//	f[1] = 1; 
//	for (auto i: e[1])
//		srh(i.to, 1);
	int tot = 0;
	for (int i = 1; i <= k; i++) {
		int x;
		scanf("%d", &x);
		x = id[x];
		dfs(x, p[x]);
	/*	for (auto j: e[x]) {
			cout << "to " << j.to << endl;
			cout << g[j.to] << endl; 
			cout << cnt1[j.to] << " " << cnt2[j.to] << endl;
			for (auto y: e[j.to])
				cout << "tto " << y.to << endl;
		}
		cout << x << " to " << p[x] << endl;
		cout << cnt1[x] << " " << cnt2[x] << endl;
		cout << g[x] << "???";*/
		dfs(p[x], x);
	//	cout << cnt1[p[x]] << " " << cnt2[p[x]] << endl;
		int ans = 1ll * g[x] * g[p[x]] % mod; 
	//	cout << g[x] << " " << g[p[x]] << endl;
//		int ans = 1ll * g[x] * f[x] % mod;
	//	printf("%d\n", ans);
		tot = (tot + ans) % mod;
	}
	cout << tot << endl;
}

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int T;
	read(ID), read(T);
	while (T--)
		slv();
	return 0;
} 
/*
7 1
5 2
1 2
1 3
2 4
2 5
1 3

0 1
5 3
1 2
1 3
1 4
1 5
1 2 3 
*/
