#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pir pair<int, int>
const int N = 1e5 + 5, mod = 1e9 + 7;
int T, typ, n, m, u[N], v[N], st, x, ans, tot;
int f[N], jc[N];
bool vis[N];
vector<pir> to[N];
vector<int> To[N];

inline void build(int u, int fa, int id){
	for(auto _ : to[u]){
		int v = _.first, idv = _.second;
		if(v ^ fa){
			if(id) To[id].push_back(idv);
			build(v, u, idv);
		}
	}
}
inline void dfs(int u){
	++tot;
	f[u] = jc[To[u].size()];
	for(auto v : To[u])
		dfs(v), f[u] = f[u] * f[v] % mod;
}
inline void jvhua(){
	tot = n - 1;
	ans = (m * jc[tot - 1] % mod - m * (m - 1) / 2 * jc[tot - 2] % mod + mod) % mod;
	printf("%lld\n", ans);
}
signed main(){
	jc[0] = 1;
	for(int i = 1; i < N; ++i) jc[i] = jc[i - 1] * i % mod;
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin >> typ >> T;
	while(T--){
		ans = 0;
		scanf("%lld%lld", &n, &m);
		for(int i = 1; i <= n; ++i) to[i].clear(), To[i].clear(), vis[i] = false;  
		for(int i = 1; i < n; ++i) scanf("%lld%lld", &u[i], &v[i]), to[u[i]].push_back({v[i], i}), to[v[i]].push_back({u[i], i});
		for(int i = 1; i <= n; ++i)
			if(to[i].size() == 1){
				st = to[i][0].second;
				build(i, 0, 0);
				break;
			}
		for(int i = 1; i <= m; ++i) scanf("%lld", &x), vis[x] = true;
		if(m == 1) dfs(st), printf("%lld\n", f[st]);  
		else if(typ == 18) puts("1");
		else if(19 <= typ && typ <= 21) jvhua();
		else puts("What can i say?");
	}
	return 0;
}

