#include <iostream>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
ll c,T,n,k,u,v,e,a[100005];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	while (T--)
	{
		cin>>n>>k;
		for (int i=1;i<=n-1;i++)
			cin>>u>>v;
		for (int i=1;i<=k;i++)
			cin>>e;
		if (c==18)
		{
			cout<<1<<endl;
			continue;
		}
		a[1]=1;
		for (int i=2;i<=n-2;i++)
			a[i]=a[i-1]*i%MOD;
		cout<<(k*a[n-2]%MOD-k*(k-1)/2*a[n-3]%MOD+MOD)%MOD<<endl;
	}
	return 0;
}
