#include<iostream>
#include<vector> 
using namespace std;
using ll = long long;
const int N = 1e5 + 7;
const ll mod = 1e9 + 7, inv2 = 500000004;
int read() {
	int x = 0;
	char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	while(c >= '0' && c <= '9') {
		x = x * 10 + (c - '0'); 
		c = getchar();
	}
	return x;
}
int c,T,n,k,cnt,e[N],gd[N][2];
ll veck[N],vec[N];
ll jc[N];
int main() {
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	c = read(), T = read(); 
	jc[0] = 1;
	for(int i=1;i<=(int)(1e5);++i) {
		jc[i] = jc[i-1] * i % mod;
	}
	while(T--) {
		cnt = 0;
		n = read(), k = read();
		for(int i=1;i<=n;++i) vec[i] = 0,gd[i][0] = gd[i][1] = 0, veck[i] = 0;
		for(int i=1,u,v;i<n;++i) {
				u = read(),v = read();
			++cnt;
			vec[u] += 1, vec[v] += 1;
			gd[cnt][0] = u, gd[cnt][1] = v;
		}
		for(int i=1;i<=k;++i) e[i] = read();
		for(int i=1;i<=k;++i) {
			if(vec[gd[e[i]][0]] == 1 || vec[gd[e[i]][1]] == 1 ||(vec[gd[e[i]][0]] == 2 && vec[gd[e[i]][1]] == 2)){
				veck[gd[e[i]][1]] += 1;
				veck[gd[e[i]][0]] += 1;
			}
		}
		ll ans = 1;	
		for(int i=1;i<=n;++i) if(vec[i] > 1) ans = ans * jc[vec[i]] % mod * inv2 % mod;
//		cout<<"ans:"<<ans<<endl;
//		cout<<"veck[2]:"<<veck[2]<<endl;
		ll tmp = 1;
		for(int i=1;i<=n;++i) {
			if(vec[i] <= 1) continue;
			if(vec[i] <= veck[i] + 1) {
//				cout<<"break"<<endl;
				tmp = 0;
				break;
			}
			else tmp = tmp * (vec[i] - veck[i]) % mod 
						   * (vec[i] - veck[i] - 1) % mod * jc[vec[i]-2] % mod * inv2 % mod;
		}
		ans  = (ans - tmp + mod) % mod;
		cout<<ans<<endl;
	}
	return 0;
}
