#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <sys/types.h>
#include <tuple>
#include <vector>

#define let const auto
#define mut auto

template<typename T>
using vec = std::vector<T>;
using ull = unsigned long long;
using ll = long long;

using std::tuple, std::array;

template<typename T>
T read() {
	T s = 0, w = 1, c = getchar();
	while (!isdigit(c)) {
		if (c == '-') {
			w = -1;
		}
		c = getchar();
	}
	while (isdigit(c)) {
		s = s * 10 + c - '0';
		c = getchar();
	}
	return s * w;
}

using Edge = tuple<uint, uint>;

class Config {
public:
	uint c, n, k;
	vec<Edge> edges;
	vec<uint> chosen;
};

uint solve(const Config &);

int main() {
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);

	let c = read<uint>();
	mut T = read<uint>();
	while (T--) {
		let n = read<uint>(), k = read<uint>();
		mut config = Config{c, n, k, vec<Edge>(n - 1), vec<uint>(k)};
		for (mut &[u, v] : config.edges) {
			u = read<uint>(), v = read<uint>();
		}
		for (mut &x : config.chosen) {
			x = read<uint>();
		}
		let ans = solve(config);
		printf("%u\n", ans);
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}

constexpr uint MOD = 1'000'000'007;

uint mul(const uint &a, const uint &b) {
	return static_cast<uint>(static_cast<ull>(a) * b % MOD);
}

uint sub(const uint &a, const uint &b) {
	return a < b ? a + MOD - b : a - b;
}

uint quick_pow(uint a, uint p) {
	uint res = 1;
	while (p) {
		if (p & 1) {
			res = mul(res, a);
		}
		p >>= 1;
		a = mul(a, a);
	}
	return res;
}

uint solve(const Config &config) {
	if (config.c == 18) {
		return 1;
	}
	if (18 <= config.c && config.c < 22) {
		let n = config.n - 1;
		let other = n - config.k;
		// printf("%u %u\n", n, other);
		mut all = 1;
		for (mut i = 1u; i <= n; i++) {
			all = mul(all, i);
		}
		// printf("%u\n", all);
		// printf("%u\n", quick_pow(mul(n, n - 1), MOD - 2));
		all = mul(all, quick_pow(mul(n, n - 1), MOD - 2));
		// printf("%u\n", sub(mul(n, n - 1), mul(other, other - 1)));
		all = mul(all, sub(mul(n, n - 1), mul(other, other - 1)));
		all = mul(all, quick_pow(2, MOD - 2));
		// printf("\n");
		return all;
	}
}