#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1000000007;

bool p;
int n, k, val[100010], u[100010], v[100010], in[100010], c, t, k1;
vector<int> edge[100010];

void dfs(int z, int x){
	if(p){
		return ;
	}
	if(z == v[val[2]]){
		p = true, k1 = z;
		return ;
	}
	if(z == u[val[2]]){
		p = true, k1 = z;
		return ;
	}
	for(int i = 0; i < edge[z].size(); i++)
		if(edge[z][i] != x && !p){
			dfs(edge[z][i], z);
		}
}

void solve(){
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		in[i] = 0, edge[i].clear();
	for(int i = 1; i < n; i++){
		scanf("%lld%lld", &u[i], &v[i]);
		in[u[i]]++, in[v[i]]++;
		edge[u[i]].push_back(v[i]);
		edge[v[i]].push_back(u[i]);
	}
	for(int i = 1; i <= k; i++)
		scanf("%lld", &val[i]);
	if(k == 1){
		int ans = 1;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j < in[i]; j++)
				ans = ans * j % mod;
		cout << ans << '\n';
		return ;
	}
	if(c == 18){
		cout << 1 << '\n';
		return ;
	}
	if(c >= 19 && c <= 21){
		if(n == 3){
			cout << 1 << '\n';
			return ;
		}
		int ans1 = k * (n - 1 - k) % mod, ans2 = k * k % mod;
		for(int i = 1; i <= n - 3; i++)
			ans1 = ans1 * i % mod, ans2 = ans2 * i % mod;
		cout << (ans1 + ans2 * ((mod + 1) / 2) % mod) % mod << '\n';
		return ;
	}
	if(k == 2){
		int ans1 = 2;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j < in[i]; j++)
				ans1 = ans1 * j % mod;
		if(u[val[1]] == u[val[2]]){
			int ans = 1;
			for(int i = 1; i <= n; i++)
				for(int j = 2; j < in[i] - (i == u[val[1]]); j++)
					ans = ans * j % mod;
			cout << (ans1 - ans + mod) % mod << '\n';
			return ;
		}
		if(u[val[1]] == v[val[2]]){
			int ans = 1;
			for(int i = 1; i <= n; i++)
				for(int j = 2; j < in[i] - (i == u[val[1]]); j++)
					ans = ans * j % mod;
			cout << (ans1 - ans + mod) % mod << '\n';
			return ;
		} 
		if(v[val[1]] == u[val[2]]){
			int ans = 1;
			for(int i = 1; i <= n; i++)
				for(int j = 2; j < in[i] - (i == v[val[1]]); j++)
					ans = ans * j % mod;
			cout << (ans1 - ans + mod) % mod << '\n';
			return ;
		}
		if(v[val[1]] == v[val[2]]){
			int ans = 1;
			for(int i = 1; i <= n; i++)
				for(int j = 2; j < in[i] - (i == v[val[1]]); j++)
					ans = ans * j % mod;
			cout << (ans1 - ans + mod) % mod << '\n';
			return ;
		}
		p = false;
		dfs(u[val[1]], v[val[1]]);
		if(p){
			int ans = 1;
			for(int i = 1; i <= n; i++){
				for(int j = 2; j < in[i] - (i == u[val[1]]) - (i == k1); j++)
					ans = ans * j % mod;
			}
			cout << (ans1 - ans + mod) % mod << '\n';
			return ;
		}
		dfs(v[val[1]], u[val[1]]);
		if(p){
			int ans = 1;
			for(int i = 1; i <= n; i++)
				for(int j = 2; j < in[i] - (i == v[val[1]]) - (i == k1); j++)
					ans = ans * j % mod;
			cout << (ans1 - ans + mod) % mod << '\n';
			return ;
		}
		return ;
	}
}

signed main(){
	freopen("traverse.in", "r", stdin);
	freopen("traverse.out", "w", stdout);
	cin >> c >> t;
	for(int i = 1; i <= t; i++)
		solve();
	return 0;
}
