#include <bits/stdc++.h>
#define C__ const
#define int long long
using namespace std;
inline void filopen(string path) {
	cin.tie(0)->sync_with_stdio(0);
	freopen((path + ".in").c_str(), "r", stdin);
	freopen((path + ".out").c_str(), "w", stdout);
}
C__ int N_ = 1e5 + 10, Mod = 1e9 + 7;
int fpow(int a, int b) { int c = 1; for (; b; (a *= a) %= Mod, b >>= 1) if (b & 1) (c *= a) %= Mod; return c; }
int C, T;
int n, m, a[N_], fac[N_];
vector<pair<int, int> > h[N_];
vector<int> g[N_];
void dfs(int u, int f) {
	for (auto ___ : h[u]) {
		int v, idx; tie(v, idx) = ___;
		if (idx != f) {
			g[f].push_back(idx);
			g[idx].push_back(f);
			dfs(v, idx);
		}	
	}
}
namespace Task1 {
	bool check() { return m <= 1; }
	int calc(int u, int p) {
		int res = 1, cnt = 0;
		for (int v : g[u])
		if (v != p)
			(res *= calc(v, u)) %= Mod, ++cnt;
		return res * fac[cnt] % Mod;
	}
	void main() { cout << calc(a[1], 0) << "\n"; }
}
namespace Task2 {
	bool check() { return C == 18; }
	void main() { cout << 1 << "\n"; }
}
void slove() {
	cin >> n >> m;
	fac[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % Mod;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		h[u].push_back({v, i});
		h[v].push_back({u, i});
	} dfs(1, 0);
	for (int i = 1; i <= m; i++) cin >> a[i];
	if (Task2::check()) return Task2::main();
	if (Task1::check()) return Task1::main();
}
void celar() {
	for (int i = 1; i <= n; i++) {
		g[i].clear(), h[i].clear(), a[i] = 0;
	}
}
signed main() {
	filopen("traverse"); 
//	freopen("traverse3.in", "r", stdin);
	cin >> C >> T;
	while (T--) slove(), celar();
	return 0;
}
