#include<bits/stdc++.h>
using namespace std;
int n,k,t,dp[200009],f[200009],nf[200009],pc[200009],pu[200009];
bool hatch[200009];
int s[200009],ni[200009],inv[200009],ssz[200009];
int ans = 0;
vector<int>e[200009];
#define mod 1000000007
void srh1(int v,int fa){
	f[v] = nf[v] = 1;
	ssz[v] = 0;
	if(v > n){
		if(hatch[v - n])
			ssz[v] = 1;
		for(int i = 0; i < e[v].size(); i ++){
			if(e[v][i] == fa)
				continue;
			srh1(e[v][i],v);
			f[v] = 1ll * f[v] * f[e[v][i]] % mod;
			nf[v] = 1ll * nf[v] * nf[e[v][i]] % mod;
			ssz[v] += ssz[e[v][i]];
		}
	}
	else{
		int o = 0;
		for(int i = 0; i < e[v].size(); i ++){
			if(e[v][i] == fa)
				continue;
			srh1(e[v][i],v);
			f[v] = 1ll * f[v] * f[e[v][i]] % mod;
			nf[v] = 1ll * nf[v] * nf[e[v][i]] % mod;
			o ++;
			ssz[v] += ssz[e[v][i]];
		}
		f[v] = 1ll * f[v] * s[o] % mod;
		nf[v] = 1ll * nf[v] * ni[o] % mod;
	}
//	printf("%d %d %d\n",v,f[v],nf[v]);
}
void srh2(int v,int fa,int d){//d for push down
	dp[v] = 1ll * f[v] * d % mod;
	//printf("%d %d\n",v,dp[v]);
	if(v > n){
		if(hatch[v - n])
			ans = (ans + dp[v]) % mod;
		for(int i = 0; i < e[v].size(); i ++){
			if(e[v][i] == fa || ssz[e[v][i]] == 0)
				continue;
			int u = 1ll * dp[v] * nf[e[v][i]] % mod;
			srh2(e[v][i],v,u);
 		}
	}
	else{
		int sp = e[v].size() - 1;
		if(sp == 0)
			return;
		for(int i = 0; i < e[v].size(); i ++){
			if(e[v][i] == fa || ssz[e[v][i]] == 0)
				continue;
			int u = 1ll * dp[v] * nf[e[v][i]] % mod;
			srh2(e[v][i],v,u);
		}
	}
}
void srh3(const int v,const int fa,const int d){
	pc[v] = 1ll * d * f[v] % mod;
	//printf("%d %d\n",v,pc[v]);
	if(v > n && hatch[v - n])
		ans = (mod + ans - pc[v]) % mod;
	pu[v] = 0;
	if(v > n){
		int u = hatch[v - n] ? dp[v] : pc[v];
		if(hatch[v - n])
			pu[v] = f[v];
		for(int i = 0; i < e[v].size(); i ++){
			if(e[v][i] == fa || ssz[e[v][i]] == 0)
				continue;
			int o = 1ll * u * nf[e[v][i]] % mod;
			srh3(e[v][i],v,o);
			if(hatch[v - n]){
				continue;
			}
			int sp = pu[v];
			pu[v] = (pu[v] + 1ll * f[v] * nf[e[v][i]] % mod * pu[e[v][i]] % mod) % mod;
			pu[v] = (mod + pu[v] - 1ll * sp * nf[e[v][i]] % mod * pu[e[v][i]] % mod) % mod;
			int p = u;
			u = (u + 1ll * dp[v] * nf[e[v][i]] % mod * pu[e[v][i]] % mod) % mod;
			u = (mod + u - 1ll * p * nf[e[v][i]] % mod * pu[e[v][i]] % mod) % mod;
		}
	}
	else{
		int sp = e[v].size() - 1;
		if(sp == 0)
			return;
		int u = 1ll * pc[v] * ni[sp] % mod * s[sp - 1] % mod;
		for(int i = 0; i < e[v].size(); i ++){
			if(e[v][i] == fa || ssz[e[v][i]] == 0)
				continue;
		//	printf("%d %d %d\n",v,e[v][i],pu[v]);
			int o = 1ll * u * nf[e[v][i]] % mod;
			srh3(e[v][i],v,o);
			pu[v] = (pu[v] + 1ll * f[v] * nf[e[v][i]] % mod * pu[e[v][i]] % mod * ni[sp] % mod * s[sp - 1] % mod) % mod;
			u = (u + 1ll * dp[v] * nf[e[v][i]] % mod * pu[e[v][i]] % mod * ni[sp] % mod * s[sp - 1] % mod) % mod;
		}
	}
	//printf(" %d %d\n",v,pu[v]);
}
char rc(){
	static char buf[100009],*p1 = buf,*p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,100009,stdin),p1 == p2) ? EOF : *p1 ++;
}
void read(int &x){
	x = 0;
	char c = ' ';
	while(c > '9' || c < '0')
		c = rc();
	while(c >= '0' && c <= '9')
		x = x * 10 + c - '0',c = rc(); 
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	read(t),read(t);
	while(t--){
		ans = 0;
		read(n),read(k);
		for(int i = 1; i < (n << 1); i ++){
			hatch[i] = false;
			e[i] = vector<int>(0);
		}
		for(int i = 1; i < n; i ++){
			int u,v;
			read(u),read(v);
			e[u].push_back(i + n);
			e[v].push_back(i + n);
			e[i + n].push_back(u);
			e[i + n].push_back(v);
		}
		int o;
		for(int i = 1; i <= k; i ++){
			read(o);
			hatch[o] = true;
		}
		o += n;
		inv[1] = s[1] = s[0] = ni[0] = ni[1] = 1;
		for(int i = 2; i <= n; i ++){
			inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
			ni[i] = 1ll * ni[i - 1] * inv[i] % mod;
			s[i] = 1ll * s[i - 1] * i % mod;
		}
		srh1(o,0);
		dp[o] = f[o];
		srh2(o,0,1);
		//puts("O");
		srh3(o,0,0);
		printf("%d\n",ans);
	}
} 
