#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fo(i,a,b) for(int i=(a);i<=(b);i++)
#define de(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const ll N=1e5+50,M=+50,L=1e5;
const ll inf=1e9,P=1e9+7;
ll read(){
	ll x=0,f=0;char c=getchar();
	while(c<'0'||c>'9') f|=(c=='-'),c=getchar();
	while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();
	return f?-x:x;
}
int c,T,n,k;
ll fac[N];
ll qpow(ll a,ll b){
	ll res=1;
	for(;b;b>>=1,a=a*a%P) if(b&1) res=res*a%P;
	return res;
}
void worka(){
	n=read(),k=read();
	fo(i,1,n-1) read(),read();
	fo(i,1,k) read();
	printf("1\n");
}
void workb(){
	n=read(),k=read();
	fo(i,1,n-1) read(),read();
	fo(i,1,k) read();
	ll res=0;
	fo(i,1,k){
		res=(res+1ll*fac[n-3]*(n-1-i)%P)%P;
	}
	printf("%lld\n",res);
}
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=1;
	fo(i,1,L) fac[i]=fac[i-1]*i%P;
	c=read(),T=read();
	while(T--){
		if(c==18) worka();
		if(c>=19&&c<=21) workb();
	}
	return 0;
}
