#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 1e5 + 5, MOD = 1e9 + 7;

int subtask_id;

ll fac[N];

inline int read() {
	int flg = 1;
	int ret = 0;
	char ch;
	ch = getchar();
	while (!('0' <= ch && ch <= '9') && !(ch == '-'))
		ch = getchar();
	if (ch == '-') {
		flg = -1;
		ch = getchar();
	}
	do {
		ret = ret * 10 + ch - '0';
		ch = getchar();
	} while ('0' <= ch && ch <= '9');
	return ret;
}

ll fpow(ll a, ll b, ll p) {
	ll mul = 1;
	while (b) {
		if (b & 1)
			mul = mul * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return mul;
}

int n, k; //结点数量，关键边数量 
struct Edge {
	int to, id;
	Edge(int t = 0, int i = 0) {
		to = t, id = i;
	}
};
vector<Edge> e[N * 2]; //点的图

int cnt;
vector<int> e2[N * 2]; 
void build() {
	cnt = n - 1;
	for (int i = 1; i <= n; i++) {
		if (e[i].size() == 1)
			;
		else if (e[i].size() == 2) {
			e2[e[i][0].id].push_back(e[i][1].id);
			e2[e[i][1].id].push_back(e[i][0].id);
		}
		else {
			cnt++;
			for (auto j: e[i]) {
				e2[j.id].push_back(cnt);
				e2[cnt].push_back(j.id);
			}
		}
	}
}
int rt;
ll dp[N * 2];

void dfs(int x, int pr) {
	dp[x] = 1;
	for (auto i: e2[x])
		if (i != pr) {
			dfs(i, x);
			dp[x] = dp[x] * dp[i] % MOD;
		}
	if (x > n - 1) {
		dp[x] = dp[x] * fac[(int)e2[x].size() - 1] % MOD;
	}
}

void slv() {
	n = read();
	k = read();
	for (int i = 1; i <= n * 2; i++) { //清空邻接表 
		while (!e[i].empty())
			e[i].pop_back();
		while (!e2[i].empty())
			e2[i].pop_back();
	}
	
	for (int i = 1, u, v; i < n; i++) {
		u = read();
		v = read();
		e[u].push_back(Edge(v, i));
		e[v].push_back(Edge(u, i));
	}
	if (subtask_id == 18) { //4pts
		puts("1");
		return ;
	}
	if (19 <= subtask_id && subtask_id <= 21) { //12pts
		for (int i = 1; i <= k; i++)
			rt = read();
		ll sum = 0;
		for (int i = 1; i <= k; i++) {
			ll tmp = ((fac[n - 2] - fac[n - 3] * (i - 1) % MOD) % MOD + MOD) % MOD;
			sum = (sum + tmp) % MOD;
		}
		cout << sum << endl;
		return ;
	}
	build();
	if (k == 1) { //24pts
		rt = read();
		dfs(rt, 0);
		printf("%lld\n", dp[rt]);
		return ;
	}
	if (k == 2) {
		ll sum = 0;
		ll rt1, rt2;
		rt1 = read();
		dfs(rt1, 0);
		sum = dp[rt1];
		rt2 = read();
		dfs(rt2, 0);
		sum = (sum + dp[rt2]) % MOD;
		sum = (sum - dp[rt1] + MOD) % MOD;
		cout << sum << endl;
		return ;
	}
	ll sum = 0;
	for (int i = 1; i <= k; i++) {
		rt = read();
		dfs(rt, 0);
		sum = (sum + dp[rt]) % MOD;
	}
	cout << sum << endl;
} 

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);

	fac[0] = 1;
	for (int i = 1; i <= 100000; i++)
		fac[i] = fac[i - 1] * i % MOD;
	
	int T;
	subtask_id = read();
	T = read();
	while (T--)
		slv(); 
	return 0;
}
