#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 1e5 + 10;
const LL H = 7, P = 1e9 + 7;
LL n, k, que[N];
LL fact[N];
struct node {
	int u, v;
} e[N];
vector<int> g[N];
LL ksm(LL a, LL b) {
	LL res = 1;
	while(b > 0) {
		if(b & 1) res *= a, res %= P;
		a *= a; a %= P;
		b >>= 1;
	}
	return res;
}
namespace sub1 {
	set<LL> st;
	void Main() {
		st.clear();
		for(int i = 1; i <= k; i++) {
//			dfs(que[i]);
		}
		cout << st.size() << '\n';
	}
}
namespace sub2 {
	void Main() {
		LL ans = 0;
		for(LL i = 1; i <= k; i++) {
			ans += ((fact[n - 1] - ((fact[n - 2] * (LL)(i - 1)) % P)) % P + P) % P; ans = (ans % P + P) % P;
		}
		cout << ans << '\n';
	}
}
int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int C = 0, T = 0; cin >> C >> T;
	fact[0] = 1;
	for(LL i = 1; i <= 1e5 + 5; i++) fact[i] = fact[i - 1] * (LL)i % P;
	while(T--) {
		cin >> n >> k;
		for(int i = 1; i <= n; i++) g[i].clear();
		for(int i = 1; i < n; i++) {
			cin >> e[i].u >> e[i].v;
			g[e[i].u].push_back(e[i].v); g[e[i].v].push_back(e[i].u);
		}
		for(int i = 1; i <= k; i++) {
			cin >> que[i];
		}
		if(C <= 17) sub1::Main();
		else if(C == 18) cout << 1 << '\n';
		else if(C >= 19 && C <= 21) sub2::Main();
//		cout << n << ' ' << k << '\n';
	}
	return 0;
}
