#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5;
const int mod=1e9+7;
struct Edge{int u,v,flg,nxt;};
int n,m;
int dg[maxn+5];
int hd[maxn+5],et;
Edge e[(maxn<<1)+5];
int sm[maxn+5];
int fac[maxn+5];
int inv[maxn+5];
int ans;
namespace IO{
    inline int Read(){
        int res=0;char ch=getchar();
        while(ch<'0'||'9'<ch) ch=getchar();
        while('0'<=ch&&ch<='9')
            res=(res<<1)+(res<<3)+ch-'0',ch=getchar();
        return res;
    }
}
using IO::Read;
inline void Adde(int u,int v){
    e[et]=Edge({u,v,0,hd[u]});
    hd[u]=et++;
}
inline int Fpow(int x,int y){
    int res=1;
    for(;y;y>>=1,x=1ll*x*x%mod)
        if(y&1) res=1ll*res*x%mod;
    return res;
}
void Dfs(int u,int fa,bool flg){
    int v;
    int pw=0;
    sm[u]=0;
    for(int i=hd[u];~i;i=e[i].nxt){
        v=e[i].v;
        if(v==fa) continue;
        Dfs(v,u,e[i].flg);
        sm[u]=(sm[u]+sm[v])%mod;
        pw=(pw+1ll*sm[v]*sm[v])%mod;
    }
    if(dg[u]>=2){
        int rs=1ll*fac[dg[u]-2]*inv[dg[u]-1]%mod;
        ans=(ans-1ll*(1ll*sm[u]*sm[u]-pw)%mod*inv[2]%mod*rs%mod)%mod;
        sm[u]=1ll*sm[u]*rs%mod;
        if(flg) ans=(ans-sm[u])%mod;
    }
    if(flg) sm[u]=(sm[u]+1)%mod;
}
inline void Solve(){
    int u,v;
    n=Read(),m=Read();
    et=0;
    for(int i=1;i<=n;i++)
        hd[i]=-1,dg[i]=0;
    for(int i=1;i<n;i++){
        u=Read(),v=Read();
        dg[u]++,dg[v]++;
        Adde(u,v);
        Adde(v,u);
    }
    for(int i=1;i<=m;i++){
        u=Read()-1;
        e[u<<1].flg=1;
        e[u<<1|1].flg=1;
    }
    ans=m;
    Dfs(1,0,0);
    for(int i=1;i<=n;i++)
        ans=1ll*ans*fac[dg[i]-1]%mod;
    printf("%d\n",(ans+mod)%mod);
}
signed main(){
    freopen("traverse.in","r",stdin);
    // freopen("traverse5.in","r",stdin);
    freopen("traverse.out","w",stdout);
    fac[0]=1;
    for(int i=1;i<=maxn;i++)
        fac[i]=1ll*fac[i-1]*i%mod;
    inv[maxn]=Fpow(fac[maxn],mod-2);
    for(int i=maxn-1;i>=0;i--)
        inv[i]=1ll*inv[i+1]*(i+1)%mod;
    int tcnt;
    Read();tcnt=Read();
    while(tcnt--) Solve();
    return 0;
}