#include<bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
bool vis[MAXN];
vector<pair<int, int> > g[MAXN];
unsigned int fa[MAXN], dep[MAXN], e[MAXN];
int T, n, k;

long long cheat(int n, int &k) {
	long long res = 1;
	for(int i = 1; i <= k; i++) {
		res = (res*(n-i+1)/i)%MOD;
	}
	return res;
}

int LCA(int u, int v) {
	//if(mp[make_pair(u, v)]) {
		//return mp[make_pair(u, v)];
	//}
	int x = u, y = v;
	while(dep[u] > dep[v]) {
		u = fa[u];
	}
	while(dep[v] > dep[u]) {
		v = fa[v];
	}
	while(u != v) {
		u = fa[u];v = fa[v];
	}
	//mp[make_pair(x, y)] = dep[u];
	//cout << "u:" << u << " dep:" << dep[u] << '\n';
	return dep[u];
}

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	int c;
	cin >> c >> T;
	while(T--) {
		cin >> n >> k;
		for(int i = 1; i < n; i++) {
			int u, v;
			cin >> u >> v;
			g[u].push_back(make_pair(u, v) );
			g[v].push_back(make_pair(v, u) );
		}
		for(int i = 1; i <= k; i++) {
			cin >> e[i];
		}
		cout << cheat(n-2, k)%MOD << '\n';
	}
	
	return 0;
}
