#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7,N=1e5+5;
int n,m,fac[N],id,t,x,y;
signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&id,&t);
	fac[0]=1; for(int i=1;i<=100000;i++) fac[i]=fac[i-1]*i%mod;
	while(t--){
		scanf("%lld%lld",&n,&m);
		for(int i=1;i<n;i++) scanf("%lld%lld",&x,&y);
		for(int i=1;i<=m;i++) scanf("%lld",&x);
		if(id==18) puts("1");
		else printf("%lld\n",(m*fac[n-2]%mod-(n>2?m*(m-1)/2%mod*fac[n-3]%mod:0)+mod)%mod);
	}
	return 0;
}

