#include<bits/stdc++.h>
using namespace std;
const long long Z=1000000007;
long long Ac(int x){
	long long ans=1;
	for(int i=2;i<=x;i++){
		ans=ans*i%Z;
	}
	return ans;
}
int c,t;
int n,k;
int u[100001],v[100001],e[100001];
bool A=1,B=1;
int main(){
	freopen("traverse10.in","r",stdin);
	freopen("traverse.out","w",stdout);
	scanf("%d%d",&c,&t);
	while(t--){
		A=B=1;
		scanf("%d%d",&n,&k);
		for(int i=1;i<n;i++){
			scanf("%d%d",&u[i],&v[i]);
			if(u[i]>v[i]){
				swap(u[i],v[i]);
			}
			if(u[i]>1){
				B=0;
			}
			if(u[i]+1!=v[i]){
				A=0;
			}
		}
		for(int i=1;i<=k;i++){
			scanf("%d",&e[i]);
		}
		if(A){
			puts("1");
			continue;
		}
		if(B){
			printf("%lld\n",(Z*2+Ac(n-2)*k%Z-(k)*(k-1)/2%Z*Ac(n-3)%Z)%Z);
		}
	}
}
