#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int c,t;
int n,k;
void sub2(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=2*(n-1)+k;i++){
		int x;scanf("%d",&x);
	}
	printf("%d\n",1);
}
void sub3(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=2*(n-1)+k;i++){
		int x;scanf("%d",&x);
	}
	int ans=1;
	for(int i=1;i<=n-2;i++)ans=1ll*ans*i%mod;
	printf("%d\n",1ll*(1ll*((n-1)+(n-k))*k/2)%mod*ans%mod);
}
int main(){
	freopen("traverse.in","r",stdin);freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&t);
	while(t--){
		if(c==18)sub2();
		if(c==19||c==20)sub3();
	}
}
