#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int p=1e9+7;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int c,T,n,k,res,ans;
int main()
{
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c=read(),T=read();
	while(T--)
	{
		n=read(),k=read();
		for(int i=1;i<n;i++) read(),read();
		for(int i=1;i<=k;i++) read();
		res=ans=1;
		for(int i=1;i<=n-3;i++) res=1ll*res*i%p;
		ans=1ll*(1ll*k*(k-1)/2%p+1ll*k*(n-k-1)%p)%p*res%p;
		printf("%d\n",ans);
	}
	return 0;
}
