#include<bits/stdc++.h>
#define m0(a) memset(a,0,sizeof(a))
#define f(i,l,r) for(int i=l;i<=r;++i)
#define endl '\n'
#define int long long 
using namespace std;
const int N=1e5,mod=1e9+7;
int c,T,n,k;
int jc(int x)
{
	int ans=1;
	f(i,2,x) ans=ans*i%mod;
	return ans;
}
signed main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
//	freopen("traverse10.in","r",stdin);
//	freopen("t10.ans","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>c>>T;
	while(T--)
	{
		cin>>n>>k;
		f(i,1,n-1) {
			int x,y; cin>>x>>y;
		} 
		f(i,1,k){
			int e;  cin>>e;
		}
		if(c==18) cout<<1<<endl;
		else if(c>=19&&c<=21) 
		{
			cout<<k*jc(n-2)%mod<<endl;
		}
	}
	return 0;
}


