#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 100005
ll c,T,n,k,a[N],fac[N];
vector<ll> e[N];
const ll mod=1000000007;
inline ll qpow(ll a,ll b,ll res=1){
	a%=mod,b%=mod;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod,b>>=1;
	} return res;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&c,&T);
	fac[0]=1;
	for(ll i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
	while(T--){
		scanf("%lld%lld",&n,&k);
		for(ll i=1;i<=n;i++) e[i].clear();
		for(ll i=1,u,v;i<n;i++) scanf("%lld%lld",&u,&v),e[u].pb(v),e[v].pb(u);
		for(ll i=1;i<=k;i++) scanf("%lld",&a[i]);
		if(c==18){printf("1\n");continue;}
		if(19<=c&&c<=21){printf("%lld\n",fac[n-1]);continue;}
	}
	return 0;
}
