#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N = 1e5 + 5,mod = 1e9 + 7,inv2 = (mod + 1) / 2;
vector<int> g[N];
int qwq,t,n,k,u,v,e[N],frac[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin >> qwq >> t;
	while(t--){
		cin >> n >> k;
		frac[0] = 1;
		for(int i = 1;i <= n;i++)g[i].clear(),frac[i] = frac[i - 1] * i % mod;
		for(int i = 1;i < n;i++){
			cin >> u >> v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for(int i = 1;i <= k;i++)cin >> e[i];
		if(n == 2){
			cout << "1\n";
			continue;
		}
		if(k == 1){
			int ans = 1;
//			for(int i = 1;i <= n;i++){
//				ans = ans * g[i].size() % mod;
//			}
//			ans = ans * g[e[1]].size() % mod;
			for(int i = 1;i <= n;i++){
				if(g[i].size() > 1)ans = ans * frac[(g[i].size() - 1)] % mod;
			}
			cout << ans << endl;
		}else if(k == 2){
			
		}else if(qwq == 18){
			cout << "1\n";
		}else if(qwq == 19){
			if(n == 2)cout << "1\n";
			else cout << (k * frac[n - 2] % mod + mod - k * (k - 1) % mod * inv2 % mod * frac[n - 3] % mod) % mod << endl;
		}
	}
}
