#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9+7;
const int maxn = 5e5+10;
int n,m;
pair<int,int>p[maxn];
vector<int>vec[maxn];
int a[maxn];
int dp[maxn];
void dfs(int x,int fa){
	int son = 0,res = 1;
	for(auto to:vec[x]){
		if(to==fa)continue;
		dfs(to,x);
		son++;
		res*=son;
		dp[x]+=dp[to];
	}
	dp[x]+=res;
	
}
void clear(){
	for(int i = 1;i<=n;i++){
		vec[i].clear();
	}
}
void solve(){
	int A=1,B=1;clear();
	clear();
	cin>>n>>m;
	for(int i = 1,u,v;i<n;i++){
		cin>>u>>v;
		if(u!=i||v!=i+1)A = 0;
		if(u!=1||v!=i+1)B = 0;
		vec[u].push_back(v);
		vec[v].push_back(u);
		p[i]={u,v};
	}
	for(int i = 1;i<=m;i++){
		cin>>a[i];
	}
	if(A){
		cout<<1<<'\n';
		return;
	}
	if(B){
		int res = 1,ans = 0,lin = 1;
		for(int i = 2;i<=n-2;i++){
			(res*=i)%=mod;
			if(i<=n-3)(lin*=i)%=mod;
		}
		for(int i = m-1;i;i--)(ans+=(res-i*lin%mod+mod)%mod)%=mod;
		(ans+=res)%=mod;
		cout<<ans<<'\n';
		return;
	}

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