#include<bits/stdc++.h>
using namespace std;
constexpr int N=1e5+9,S=1<<22,mod=1e9+7,i2=(mod+1)>>1;
char buf[S],*p1,*p2;
inline int nc(){
if(p1==p2){
p2=(p1=buf)+cin.read(buf,S).gcount();
if(p1==p2)return EOF;
}return *p1++;
}
inline int rd(){
char ch;
while(!isdigit(ch=nc()));
int x=ch&0xf;
while(isdigit(ch=nc()))x=x*10+(ch&0xf);
return x;
}
inline void mul(int&x,int y){
x=1ll*x*y%mod;
}
int n,k,eu[N],ev[N],fa[N],f[N],g[N],h[N],fac[N];
bool isk[N],isn[N];
vector<int>es[N];
void dfs(int x){
for(int y:es[x]){
es[y].erase(find(es[y].begin(),es[y].end(),x));
fa[y]=x,dfs(y);
}
}
void calc(int x){
if(int c=es[x].size()){
f[x]=fac[c];
for(int y:es[x])calc(y),mul(f[x],f[y]);
int mf=1,mg=0,mh=0,mt=0;
for(int i=0;i<c;++i){
int y=es[x][i];
mul(mg,f[y]),mul(mg,i);
mul(mt,f[y]),mul(mt,i-1);
mg=(mg+1ll*g[y]*mf)%mod;
mt=(mt+1ll*h[y]*mh)%mod;
mul(mh,f[y]),mul(mh,i);
mh=(mh+1ll*h[y]*mf)%mod;
mul(mf,f[y]),mul(mf,i+1);
}
if((mh-=mt)<0)mh+=mod;
g[x]=mg,h[x]=mh;
if(x>1){
g[x]=(1ll*g[x]*c+1ll*mh*(c-1))%mod;
if(isk[x])h[x]=f[x];
else if((h[x]+=mt)>=mod)h[x]-=mod;
}
}else f[x]=1,g[x]=0,h[x]=isk[x];
}
signed main(){
freopen("traverse.in","r",stdin);
freopen("traverse.out","w",stdout);
cin.tie(nullptr)->sync_with_stdio(false);
fac[0]=1;
for(int i=1;i<N;++i)mul(fac[i]=fac[i-1],i);
for(int T=(rd(),rd());T;--T){
n=rd(),k=rd();
memset(isk+1,false,n);
memset(isn+1,false,n-1);
for(int i=1;i<=n;++i)es[i].clear();
for(int i=1;i<n;++i){
int u=eu[i]=rd(),v=ev[i]=rd();
es[u].push_back(v),es[v].push_back(u);
}
while(k--)isn[rd()]=true;
dfs(1);
for(int i=1;i<n;++i){
if(!isn[i])continue;
int u=eu[i],v=ev[i];
isk[u==fa[v]?v:u]=true;
}
calc(1);
if((g[1]+=h[1])>=mod)g[1]-=mod;
cout<<g[1]<<'\n';
}
return cout<<flush,0;
}