#include<bits/stdc++.h>
using namespace std;

const int N=100005,mod=1000000007;

int c,T,n,k;
int ck[N];
vector<pair<int,int> > g[N];

int read(){
	int ff=1,kk=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')ff=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		kk=kk*10+ch-'0';
		ch=getchar();
	}
	return ff*kk;
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read();T=read();
	while(T--){
		for(int i(1);i<=n;++i)g[i].clear();
		n=read();k=read();
		for(int i(1);i<n;++i){
			int u=read(),v=read();
			g[u].push_back({v,i});
			g[v].push_back({u,i});
		}
		for(int i(1);i<=k;++i)ck[i]=read();
		if(c==18){
			puts("1");
			continue;
		}
		if(c>=19&&c<=21){
			long long ans=1;
			for(int i(1);i<n-1;++i)ans=ans*i%mod;
			printf("%lld\n",ans%mod);
			continue;
		}
	}
	return 0;
} 
