#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
ll n,m,c,t,mod=1e9+7,ann[N];
vector<int>v[N*2];
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%lld%lld",&c,&t);
	ann[0]=1;
	for(int i=1;i<N;i++)ann[i]=ann[i-1]*i%mod;
	while(t--){
		scanf("%lld%lld",&n,&m);
		for(int i=1;i<=n*2;i++)v[i].clear();
		for(int i=1,x,y;i<n;i++){
			scanf("%d%d",&x,&y);
			v[i].push_back(x+n);
			v[i].push_back(y+n);
		}
		int f=0;
		for(int i=1;i<=m;i++)scanf("%d",&f);
		if(n<=3||c==18){
			cout<<"1\n";
			continue;
		}
		if(c>=19&&c<=21){
			ll as=ann[n-2]*m%mod;
			cout<<(ann[n-2]*m%mod-ann[n-3]*(m*(m-1)/2%mod)%mod+mod)%mod<<"\n";
		}
	}
	return 0;
}
