#include<bits/stdc++.h>
#define ll long long
#define ci const int
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define fd(i,l,r) for(int i=(l);i>=(r);--i)
using namespace std;
inline ll read(){ll u,f=1;char o;while((o=getchar())<48||o>57)if(o=='-')f=-1;u=(o^48);while((o=getchar())>=48&&o<=57)u=(u<<1)+(u<<3)+(o^48);return u*f;}
bool ST;
ci N=4e5+5,mod=1e9+7;
ll n,k,fac[N+1],a[N];
vector<int>w[N];
void add(int x,int y)
{
	w[x].push_back(y);
	w[y].push_back(x);
}
void clear()
{
	fo(i,1,n)vector<int>().swap(w[i]);
}
bool ED;
int main()
{cerr<<(&ST-&ED)/1048576.0<<'\n';
//	freopen("traverse10.in","r",stdin);
//	freopen("1.out","w",stdout);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	int id=read(),T=read();
	fac[0]=1;
	fo(i,1,N)fac[i]=fac[i-1]*i%mod;
	while(T--)
	{
		n=read();k=read();
		clear();
		fo(i,1,n-1)
		{
			int u=read(),v=read();
			add(u,v);
		}
		fo(i,1,k)a[i]=read();
		if(id==18)
		{
			cout<<1<<'\n';
			continue;
		}
		if(k==1)
		{
			ll ans=1;
			fo(i,1,n)ans=ans*fac[w[i].size()-1]%mod;
			cout<<ans<<'\n';
			continue;
		}
		cout<<((k*fac[n-2]%mod-(k*(k-1)/2)%mod*fac[n-3]%mod)%mod+mod)%mod<<'\n';
	}
}
