#include<bits/stdc++.h>
#define rg register int
#define fo(i,l,r) for(rg i=(l);i<=(r);i++)
#define dfo(i,r,l) for(rg i=(r);i>=(l);i--)
#define fe(i,x) for(rg i=hd[x];i;i=nex[i])
#define frein freopen("in.txt","r",stdin)
#define freout freopen("out.txt","w",stdout)
#define fre(p) freopen(#p".in","r",stdin),freopen(#p".out","w",stdout)
#define outa(l,r,a) {fo(i,l,r)cout<<a[i]<<" ";cout<<"\n";}
#define BZ {cout<<"-----------------\n";}
#define eb emplace_back
#define ll long long
using namespace std;
void rd(int &x){
	int v(0),op(1);
	register char c=getchar();
	while(c<'0'||'9'<c)op=c=='-'?-1:1,c=getchar();
	while('0'<=c&&c<='9')v=(v<<1)+(v<<3)+(c^48),c=getchar();
	x=v*op; 
}
#define mo 1000000007
void dec(int &x,int y){x-=y;if(x<0)x+=mo;}
int ID,T,n,k,x,y,ans,s,t;
void solve(){
	rd(n),rd(k);
	fo(i,2,n)rd(x),rd(y);
	fo(i,1,k)rd(x);
	if(ID==18){
		cout<<"1\n";
		return;
	}
	if(19<=ID&&ID<=21){
		s=1;
		fo(i,1,n-3)s=1ll*s*i%mo;
		ans=1ll*s*(n-2)%mo*k%mo;
		t=(1ll*k*(k-1)/2)%mo;
		dec(ans,1ll*s*t%mo);
		cout<<ans<<"\n";
		return;
	}
}
int main(){
//	frein;
	fre(traverse);
	rd(ID),rd(T);
	while(T--)solve();
	return 0;
}
