#include<bits/stdc++.h>
#define pb push_back
#define LL long long
using namespace std;
const int N=1e5+5;
const LL Mod=1e9+7; 
int Id,T,n,k,P[N],U[N],V[N];
vector<int>E[N];
inline void Rd(int &x,int f=1)
{
	x=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9')x=10*x+c-'0',c=getchar();
	x=x*f;
};
inline LL Ksm(LL x,LL y)
{
	LL A=1;
	while(y)
	{
		if(y&1)A=A*x%Mod;
		x=x*x%Mod,y>>=1;
	}
	return A;
}
void Work()
{
	Rd(n),Rd(k);
	for(int i=1,u,v;i<n;i++)
	{	
		Rd(U[i]),Rd(V[i]);
		E[U[i]].pb(i),E[V[i]].pb(i);
	}
	for(int i=1;i<=k;i++)Rd(P[i]);
	if(Id==18)return puts("1"),void();
	if(19<=Id&&Id<=21)
	{
		LL Ans=k,F=1;
		for(int i=1;i<=n-3;i++)F=F*i%Mod;
		for(int i=1;i<=n-2;i++)Ans=Ans*i%Mod;
		for(int i=2;i<=k;i++)Ans=(Ans-(i-1)*F%Mod+Mod)%Mod;
		return printf("%lld\n",Ans%Mod),void();
	}
}
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	Rd(Id),Rd(T);
	while(T--)Work();
}
