#include<bits/stdc++.h>
#define rep(i , m , n) for(register int i = m; i <= n; i++)

using namespace std;
const int MOD = 1e9 + 7;
int C , T;
int n , k;
int u[100005] , v[100005];
int a[100005];
int read(){
	int x = 0 , f = 1;
	char c = getchar();
	while(c < '0' || c > '9')f = (c == '-') ? -1 : 1 , c = getchar();
	while(c >= '0' && c <= '9')x = (x << 3) + (x << 1) + (c ^ 48) , c = getchar();
	return x * f;
}
int main(){
	freopen("traverse.in" , "r" , stdin);
	freopen("traverse.out" , "w" , stdout);
	C = read() , T = read();
	while(T--){
		n = read() , k = read();
		rep(i , 1 , n - 1)u[i] = read() , v[i] = read();
		rep(i , 1 , k)a[i] = read();
		if(C == 18){
			printf("1\n");
			continue;
		}
		if(C == 19 || C == 10 || C == 21){
			long long tmp = 1 ,Tmp = 1;
			int N = n - 1;
			rep(i , 1 , N - 1)(tmp *= i) %= MOD;
			rep(i , 1 , N - 2)(Tmp *= i) %= MOD;
			long long ans = ((((k * tmp) % MOD) - (((1ll * k * (k - 1) / 2) * Tmp) % MOD) + MOD)) % MOD;
			printf("%lld\n" , ans);
		}
		if(n <= 5){
			;
		}
	}
	
	
	return 0;
}
