#include<bits/stdc++.h>
#define int long long
#define up(i,l,r) for(int i=l; i<=r; ++i)
#define dn(i,r,l) for(int i=r; i>=l; --i)
#define pb push_back

using namespace std;

const int N=200005, P=1e9+7;

int ranger, T, n, m, k, u[N], v[N], ran[N], Ans=1;

void mian() {
	cin >> n >> k;
	bool flag=1;
	up(i,2,n) {
		cin >> u[i] >> v[i];
		if(u[i]!=1) flag=0;
	}
	up(i,1,k) {
		cin >> ran[i];
	}
	if(!k) {
		cout << 0 << '\n';
		return;
	}
	if(flag) {
		--n;
		int bur=1;
		up(i,1,n-2) bur=bur*i%P;
//		cout << "Qwq " << bur << ' ' << bur*(n-1)%P << '\n';
		Ans=(bur*k%P*(n-1)%P-((__int128)k*(k-1)/2)%P*bur%P)%P;
		cout << (Ans%P+P)%P << '\n';
		return;
	}
	cout << 1 << '\n';
}

signed main() {
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> ranger >> T;
	while(T--) mian();
	return 0;
}
