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

#define LL long long

void read(LL &x){
	scanf("%lld",&x);
}

void write(LL x,LL op=1){
	if(!op) printf("%lld ",x);
	else printf("%lld\n",x);
}

const LL N=1e5+10,mod=1e9+7;

LL n,k,a[N],id;

vector<LL> g[N];

struct Edge{
	LL u,v;
}edge[N];

void solve(){
	read(n),read(k);
	for(LL i=1;i<=n;i++) vector<LL>().swap(g[i]);
	for(LL i=1;i<n;i++){
		LL u,v;
		read(u),read(v);
		edge[i]={u,v};
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(LL i=1;i<=k;i++) read(a[i]);
	if(id==18){
		write(1);
		return ;
	}
	if(id>=19&&id<=21){
		LL ans=1,sum=0;
		for(LL i=1;i<=n-3;i++) ans=ans*i%mod;
		for(LL i=1;i<=k;i++) sum=(sum+(n-1-a[i])*ans%mod)%mod;
		write(sum);
		return ;
	}
}

int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	read(id);
	LL T=1;
	read(T);
	while(T--){
		solve();
	}
	return 0;
}

