#include <iostream>
#include <cstdio>
#define mod 1000000007 
using namespace std;
typedef long long ll;
ll c,t,n,k,fac[100001];
namespace sol1 {
	ll du[100001];
	void work() {
		scanf("%lld%lld",&n,&k);
		for(int i=1;i<=n;++i) du[i]=0;
		ll u,v;
		for(int i=1;i<n;++i) {
			scanf("%lld%lld",&u,&v);
			++du[u];
			++du[v];
		}
		scanf("%lld",&u);
		ll ans=1;
		for(int i=1;i<=n;++i) ans=ans*fac[du[i]-1]%mod;
		printf("%lld\n",ans);
	}
}
namespace sol2 {
	void work() {
		scanf("%lld%lld",&n,&k);
		ll u,v;
		for(int i=1;i<n;++i) scanf("%lld%lld",&u,&v);
		for(int i=1;i<=k;++i) scanf("%lld",&u);
		ll ans=fac[n-2]*k%mod;
		for(int i=1;i<k;++i) ans=(ans-i*fac[n-3])%mod;
		printf("%lld\n",(ans+mod)%mod);
	}
}
int main() {
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	fac[0]=1;
	for(int i=1;i<=100000;++i) fac[i]=fac[i-1]*i%mod;
	scanf("%lld%lld",&c,&t);
	while(t--) {
		if(c<=6) sol1::work();
		if(c==18) puts("1");
		if(19<=c&&c<=21) sol2::work();
	}
	return 0;
}
