#include<bits/stdc++.h>

#define fi first
#define se second
#define int long long

using namespace std;

int read()
{
	int s = 0,f = 1; char x = getchar();
	while(x < '0' || '9' < x) f = (x == '-') ? -1 : 1 , x = getchar();
	while('0' <= x && x <= '9') s = s * 10 + x - '0' , x = getchar();
	return s * f;
}

const int mo = 1e9 + 7;

int c,t;
int n,k;

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

	c = read();
	t = read();
	
	while(t --)
	{
		n = read();
		k = read();
		
		for (int i = 1,u,v;i < n;i ++)
		{
			u = read();
			v = read();
		}
		for (int i = 1;i <= k;i ++)
		{
			int x = read();
		}
		
		if (c == 18)
		{
			puts("1");
		}
		if (19 <= c && c <= 21)
		{
			int ans = k;
			for (int i = 1;i <= n - 2;i ++) ans = (ans * i) % mo;
			cout << ans % mo << endl;
		}
	}
	return 0;
}

/*
19 2
1000 1
100000 1

351948828
648676227
947641997
897228004
794407216
580598095
111804714
534487234
172253681
679088770

*/
