#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define ft first
#define sd second

const int N=1e5+5,P=1e9+7;

int Case,TT,n,m;
vector<int> T[N];
vector<pii> G[N];
int e[N],f[N];
int fac[N];

inline int rd()
{
    int x=0,f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')
            f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=(x<<3)+(x<<1)+(ch^48);
    return x*f;
}

void wt(const int &x)
{
    if(x<0)
        return putchar('-'),wt(-x),void();
    if(x>9)
        wt(x/10),putchar(x%10+48);
    else
        putchar(x+48);
}

void dfs1(int u,int pa,int lst)
{
    for(pii i:G[u]){
        int v=i.ft,id=i.sd;
        if(v==pa) continue;
        if(lst){
            T[id].push_back(lst);
            T[lst].push_back(id);
        }
        dfs1(v,u,id);
    }
}

void dfs2(int u,int pa)
{
    int son=0;
    f[u]=1;
    for(int v:T[u]){
        if(v==pa) continue;
        son++;
        dfs2(v,u);
        f[u]=f[u]*f[v]%P;
    }
    f[u]=f[u]*fac[son]%P;
}

void solve()
{
    // remember to clear!!
    n=rd(),m=rd();
    for(int i=1;i<=n;i++){
        G[i].clear();
        T[i].clear();
    }
    for(int i=1,u,v;i<n;i++){
        u=rd(),v=rd();
        G[u].push_back({v,i});
        G[v].push_back({u,i});
    }
    dfs1(1,0,0);
    int ans=0;
    for(int i=1;i<=m;i++){
        e[i]=rd();
        dfs2(e[i],0);
        ans=(ans+f[e[i]])%P;
    }
    wt(ans),putchar('\n');
}

signed main()
{
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    for(int i=fac[0]=1;i<=N-5;i++)
        fac[i]=fac[i-1]*i%P;
    Case=rd(),TT=rd();
    while(TT--)
        solve();
    return 0;
}
