#include<bits/stdc++.h>
using namespace std;
inline int read()
{
char c=getchar();
int x=0;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+(c&15),c=getchar();
return x;
}
const int p=1e9+7,half=(p+1)>>1;
inline int qp(int x,int y)
{
int r=1;
for(int i=x; y; y>>=1,i=1ll*i*i%p)
if(y&1) r=1ll*r*i%p;
return r;
}
vector<pair<int,int>> e[1<<17];
int fac[1<<17],ifac[1<<17];
int u[1<<17],v[1<<17],a[1<<17];
int f[1<<17],g[1<<17],h[1<<17],w[1<<17];
inline void dfs(int x,int fa)
{
int sz=e[x].size();
f[x]=g[x]=1,w[x]=h[x]=0;
for(auto i:e[x])
{
int y=i.first;
if(y==fa) continue;
dfs(y,x),f[x]=1ll*f[x]*f[y]%p,g[x]=1ll*g[x]*g[y]%p;
}
int sum=0;
for(auto i:e[x])
{
int y=i.first,id=i.second;
if(y==fa) continue;
if(a[id]) w[y]=1;
h[x]=(h[x]+1ll*h[y]*fac[sz-1]%p*g[y]%p*f[x])%p,
h[x]=(h[x]+1ll*w[y]*(sz-2)%p*fac[sz-2]%p*f[x]%p)%p,
h[x]=(h[x]+p-1ll*w[y]*sum%p*fac[sz-2]%p*f[x]%p)%p,
sum=(sum+w[y])%p,
w[x]=(w[x]+w[y])%p;
}
f[x]=1ll*f[x]*fac[sz-1]%p,g[x]=1ll*g[x]*ifac[sz-1]%p;
if(sz>=2) w[x]=1ll*w[x]*fac[sz-2]%p*ifac[sz-1]%p;
return ;
}
void HappyBirthday()
{
int n=read(),m=read();
for(int i=1; i<n; ++i) a[i]=0;
for(int i=1; i<=n; ++i) e[i].clear();
for(int i=1; i<n; ++i)
u[i]=read(),v[i]=read(),
e[u[i]].push_back({v[i],i}),
e[v[i]].push_back({u[i],i});
while(m--) a[read()]=1;
for(int i=1; i<n; ++i) if(a[i])
{
int x=u[i],y=v[i];
dfs(x,y),dfs(y,x),
printf("%lld\n",(1ll*f[x]*f[y]+1ll*f[x]*h[y]+1ll*h[x]*f[y])%p);
return ;
}
puts("0");
}
signed main()
{
#ifndef local
freopen("traverse.in","r",stdin),
freopen("traverse.out","w",stdout);
#endif
fac[0]=ifac[0]=1,assert(read()!=-1);
const int N=1e5;
for(int i=1; i<=N; ++i) fac[i]=1ll*fac[i-1]*i%p;
ifac[N]=qp(fac[N],p-2);
for(int i=N-1; i>=1; --i) ifac[i]=1ll*ifac[i+1]*(i+1)%p;
for(int T=read(); T--; HappyBirthday());
return 0;
}