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

const ll MOD = 1e9 + 7;
const int N = 1e6 + 10;
int sub, T, n, k, tot, key[N];
ll fac[N], inv[N];
struct edge{
	int u, v;
} e[N], e1[N];

ll exp(ll a, ll b){
	ll cnt = 1;
	while(b){
		if(b & 1)
			(cnt *= a) %= MOD;
		(a *= a) %= MOD, b >>= 1;
	}
	return cnt;
}

ll C(int n, int m){
	if(n < 0 || m < 0 || n < m)
		return 0;
	return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

void solve(){
	scanf("%d%d", &n, &k);
	for(int i=1;i<n;i++)
		scanf("%d%d", &e[i].u, &e[i].v);
	for(int i=1;i<=k;i++)
		scanf("%d", &key[i]);
	if(sub == 18)
		return printf("1\n"), void();
	for(int i=1;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(e[i].u == e[j].u || e[i].v == e[j].v || e[i].u == e[j].v || e[i].v == e[j].u)
				++tot;
		}
	}
	printf("%lld\n", C(tot, n - 1));
}

int main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	fac[0] = inv[0] = 1;
	for(int i=1;i<=1000000;i++)
		fac[i] = fac[i - 1] * i % MOD;
	inv[1000000] = exp(fac[1000000], MOD - 2);
	for(int i=999999;i>=1;i--)
		inv[i] = inv[i + 1] * (i + 1ll) % MOD;
	scanf("%d%d", &sub, &T);
	while(T--)
		solve();
	return 0;
}
