#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int c,T,n,k,cho[100005];
struct node{
	int a,b;
}E[100005];
long long ans;
vector<int>edge[100005];
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&T);
	while(T--){
		if(c==18){
			printf("1\n");
			continue;
		}
		ans=1;
		scanf("%d%d",&n,&k);
		for(int i=1;i<n;++i){
			int a,b;
			scanf("%d%d",&a,&b);
			edge[a].push_back(b);
			edge[b].push_back(a);
			E[i].a=a;E[i].b=b;
		}
		for(int i=1;i<=k;++i){
			scanf("%d",&cho[i]);
		}
		if(c>=19&&c<=21){
			for(int i=n-1;i>=1;i--){
				ans*=i;
				ans%=mod;
			}
		}
		printf("%d\n",ans*k%mod);
	}
}
