#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100005, mod = 1000000007;
int C, T, n, k, c[N], u[N], v[N], fac[N], inv[N], deg, vis[N], t, fl;
vector <int> e[N];
int qpow(int x, int y){
	int ans = 1;
	for(; y; y >>= 1) ans = y & 1? ans * x % mod: ans, x = x * x % mod;
	return ans;
}
void dfs(int x, int p){
	if((x == u[c[2]] || x == v[c[2]]) && !fl) vis[x] = 1, fl = 1;
	for(int i: e[x]) if(i != p) dfs(i, x);
}
void dfs2(int x, int p){
	for(int i: e[x]) if(i != p)
		dfs2(i, x), vis[x] |= vis[i];
	if(vis[x]) t = t * qpow(e[x].size() - 1, mod - 2) % mod;
}
signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin >> C >> T;
	for(int i = fac[0] = 1; i < N; i++) fac[i] = fac[i - 1] * i % mod, inv[i] = qpow(fac[i], mod - 2);
	while(T--){
		cin >> n >> k;
		for(int i = 1; i <= n; i++) e[i].clear(), vis[i] = 0;
		for(int i = 1; i < n; i++) cin >> u[i] >> v[i], e[u[i]].push_back(v[i]), e[v[i]].push_back(u[i]);
		int ans = 1;
		for(int i = 1; i <= n; i++) ans = ans * fac[e[i].size() - 1] % mod;
		for(int i = 1; i <= k; i++)
			cin >> c[i];
		int sum = ans * k % mod;
		if(k == 2 && C < 18){
			t = 1, fl = 0, dfs(u[c[1]], v[c[1]]);
			if(fl) dfs2(u[c[1]], v[c[1]]);
			else dfs(v[c[1]], u[c[1]]), dfs2(v[c[1]], u[c[1]]);
			sum = (sum + mod - ans * t % mod) % mod;
		}
		if(C == 18){ cout << "1\n"; continue;}
		if(C >= 19 && C <= 21 && n >= 3) sum = (sum + mod - k * (k - 1) / 2 % mod * fac[n - 3] % mod) % mod;
		cout << sum << '\n'; 
	}
	return 0;
}
