#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<ll,ll>
#define ve vector<ll>
#define pb push_back
#define fi first
#define se second
#define mid (l+r>>1)
using namespace std;
const ll N=2e5+2,P=1e9+7;
ll T,n,m,ans,a[N],b[N],c[N],d[N],f[N],g[N],h[N],fc[N],iv[N],iiv[N],D[N];
vector<pii>e[N];
ll ksm(ll x,ll y=P-2){
	return y?ksm(x*x%P,y>>1)*(y&1?x:1)%P:1;
}
void dfs(ll x,ll y){
	d[x]=1;
	for(pii i:e[x])
		if(i.se!=y)
			dfs(i.fi,i.se),h[x]++,
			(d[x]*=d[i.fi])%=P;
	(d[x]*=fc[h[x]])%=P,D[x]=ksm(d[x]);
	for(pii i:e[x])
		if(i.se!=y)
			(f[x]+=f[i.fi]*d[x]%P*D[i.fi]%P*iiv[h[x]])%=P;
	if(c[y])a[x]=1,g[x]=(P+P-f[x]-d[x])%P,(f[x]+=g[x])%=P;
}
void Dfs(ll x,ll y){
	if(y){
		b[x]=b[y]*d[y]%P*fc[e[y].size()-1]%P*D[x]%P*iv[h[y]]%P;
		if(a[x])(ans-=g[x]*b[x])%=P;
	}
	else b[x]=1;
	for(pii i:e[x])
		if(i.fi!=y)Dfs(i.fi,x);
	ll s=0;
	for(pii i:e[x])
		if(i.fi!=y){
			ll z=f[i.fi]*D[i.fi]%P;
			if(e[x].size()>=2)
				(ans-=z*s%P*d[x]%P*b[x]%P*iv[h[x]]%P*fc[e[x].size()-2])%=P;
			(s+=z)%=P;
		}
}
void slv(){
	cin>>n>>m,fc[0]=iv[0]=1,ans=0;
	for(ll i=1;i<=n;i++)
		fc[i]=fc[i-1]*i%P,e[i].clear(),iv[i]=ksm(fc[i])%P,
		iiv[i]=ksm(i),
		a[i]=b[i]=c[i]=d[i]=f[i]=g[i]=h[i]=D[i]=0;
	for(ll i=1,x,y;i<n;i++)
		cin>>x>>y,e[x].pb({y,i}),e[y].pb({x,i});
	for(ll i=1,x;i<=m;i++)cin>>x,c[x]=1;
	dfs(1,0),Dfs(1,0);
	cout<<(ans+P)%P<<'\n';
}
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>T>>T;
	while(T--)slv();
	cerr<<clock();
	return 0;
}