#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1000000007,ms1=100003,ms2=998244533;
int c,T,n,k,dfn[100005],maxn[100005],rd[100005],cnt,rt,ans;
ll jc[100005],ny[100005],frm[100005];
vector<int> vc[100005];
bool gd[100005],vis[100005];
struct Edge{
	int x,y;
}e[100005];
ll ksm(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b=(b>>1);
	}
	return ret;
}
ll A(int a,int b){
	if(a<=0||a>b) return 0;
	return jc[b]*ny[b-a]%mod;
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout); 
	scanf("%d%d",&c,&T);
	jc[0]=ny[0]=1;
	for(int i=1;i<=100000;i++){
		jc[i]=jc[i-1]*i%mod;
		ny[i]=ksm(jc[i],mod-2);
	}
	while(T--){
		scanf("%d%d",&n,&k);
		for(int i=1;i<n;i++){
			scanf("%d%d",&e[i].x,&e[i].y);
			vc[e[i].x].push_back(i);
			vc[e[i].y].push_back(i);
		}
		for(int i=1,eee;i<=k;i++) scanf("%d",&eee);
		if(c==18) printf("1\n");
		else if(c>=19&&c<=21){
			ll t=(jc[n-1]*ny[2]%mod-A(k,n-3)*jc[n-1-k]%mod+mod)%mod;
			printf("%lld\n",t);
		}
		else printf("%d\n",n-2);
		for(int i=1;i<=n;i++) vc[i].clear();
	}
	return 0;
}
