#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
void rd(ll &x) {
	char c;
	while (c=getchar(),!('0'<=c&&c<='9'));
	x=c-'0';
	while (c=getchar(),'0'<=c&&c<='9') x=x*10+c-'0';
}
const int I=1e9;
const ll J=1e18,N=1e5+7,P=1e9+7;
ll qp(ll x,ll y=P-2) { return y?(y&1?x:1)*qp(x*x%P,y>>1)%P:1; }
ll type,n,k,fac[N],a[N];
pll b[N]; 
vector<pll> e[N];
namespace solve1 {
	ll ans;
	void mian() {
		ans=1;
		for (ll i=1;i<=n;i++) (ans*=fac[(ll)e[i].size()-1])%=P;
		cout<<k*ans%P<<"\n";
	}
}
namespace solve2 {
	void mian() {
		cout<<"1\n";
	}
}
namespace solve3 {
	void mian() {
		if (n==2) cout<<"1\n";
		else cout<<(k*(n-1-k)%P*fac[n-3]%P+k*(k-1)/2%P*fac[n-3]%P)%P<<"\n";
	}
}
void mian() {
	rd(n),rd(k);
	for (ll i=1;i<=n;i++) e[i].clear();
	for (ll i=1,x,y;i<n;i++) rd(x),rd(y),e[x].pb({y,i}),e[y].pb({x,i}),b[i]={x,y};
	for (ll i=1;i<=k;i++) rd(a[i]); 
	if (type==18) solve2::mian();
	else if (19<=type&&type<=21) solve3::mian();
	else solve1::mian();
}
bool ORY; int main() {
	fac[0]=1;
	for (ll i=1;i<N;i++) fac[i]=fac[i-1]*i%P;
//	freopen("traverse9.in","r",stdin);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
//	while (1)
	int t; for (scanf("%lld%d",&type,&t);t--;)
	mian();
	cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB";
	return 0; 
}
