// I love Furina forever
# include <bits/stdc++.h>
# define maxn 100100
# define mod 1000000007
# define mem(a, val) memset(a, val, sizeof(a))
# define rep(i, j, k) for(int i = j; i <= k; ++i)
# define per(i, j, k) for(int i = j; i >= k; --i)
# define go(i, u) for(int i = head[u], v = to[i]; i; i = nxt[i], v = to[i])
using namespace std;

int Subtask, T;
int n, k, ans;
int head[maxn], to[maxn << 1], nxt[maxn << 1], tot;
int a[maxn], fac[maxn];
int e1[maxn], e2[maxn];

inline void add_edge(int u, int v) {nxt[++tot] = head[u], to[tot] = v; head[u] = tot;}

namespace Subtask1 {
	int f[maxn];
	
	inline void dfs(int u, int fat) {
		int deg = 0; f[u] = 1;
		go(i, u) if(v != fat) dfs(v, u), deg++, f[u] = 1ll * f[u] * f[v] % mod;
		f[u] = 1ll * f[u] * fac[deg] % mod;
	}
	
	inline void solve() {
		fac[0] = 1;
		rep(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % mod;
		int u = e1[a[1]], v = e2[a[1]];
		dfs(u, v); dfs(v, u);
		cout << 1ll * f[u] * f[v] % mod << '\n';
	}
}

namespace Subtask3 {
	inline void solve() {
		fac[0] = 1; rep(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % mod;
		cout << (1ll * k * fac[n - 2] % mod - 1ll * fac[n - 3] * (1ll * k * (k - 1) / 2 % mod) % mod + mod) % mod << '\n'; 
	}
}

signed main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);	
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> Subtask >> T;
	while(T--) {
		cin >> n >> k;
		mem(head, 0); tot = 0;
		rep(i, 1, n - 1) cin >> e1[i] >> e2[i], add_edge(e1[i], e2[i]), add_edge(e2[i], e1[i]);
		rep(i, 1, k) cin >> a[i];
		if(Subtask <= 6) {
			Subtask1::solve();
		}
		else if(Subtask == 18) {
			cout << "1\n";
		}
		else if(19 <= Subtask && Subtask <= 21)	{
			Subtask3::solve();
		}
	}
	return 0;
}

