#include<bits/stdc++.h>
#define psb push_back
typedef long long LL;
using namespace std;
inline int read(){
    char ch=getchar(); while(ch!='-' && !isdigit(ch)) ch=getchar();
    int x=0,ff=1; if(ch=='-') ff=-1,ch=getchar();
    while(isdigit(ch)) x=(x<<3) + (x<<1) + (ch^48),ch=getchar();
    return x*ff;
}
const int N=1e5+5,P=1e9+7;
int Pow(int x,int kx){ int y=1;
    while(kx){
        if(kx & 1) y=1ll*y*x%P;
        kx>>=1; x=1ll*x*x%P;
    } return y;
}
int Td,n,m,eu[N],ev[N],c[N],fa[N],bd[N],pw[N],f[N][2],f2[2],f3[2],Ans; bool vis[N]; vector<int> e[N];
void dfs1(int u,int Fa){
    fa[u]=Fa; for(int v:e[u]) if(v!=Fa) dfs1(v,u);
}
void dfs2(int u,int Fa,bool rs){
    f[u][0]=f[u][1]=1; int f1=0;
    rs|=vis[bd[fa[u]==Fa?u:Fa]]; if(rs) f[u][1]=0;
    for(int v:e[u]) if(v!=Fa) { dfs2(v,u,rs); ++f1; f[u][0]=1ll*f[u][0]*f[v][0]%P;}
    f[u][0]=1ll*f[u][0]*pw[f1]%P;
    if(f1 && f[u][1]) {
        f2[0]=1; f2[1]=0;
        for(int v:e[u]) if(v!=Fa){
            f3[0]=f3[1]=0;
            for(int o:{0,1}) for(int ov:{0,1})
                if(o+ov<2) f3[o+ov]=(f3[o+ov]+1ll*f2[o]*f[v][ov])%P;
            f2[0]=f3[0]; f2[1]=f3[1];
        }
        f[u][1]=1ll*f2[1]*pw[f1-1]%P;
    }
    // if(!f[u][1]) cout<<"adsf\n";
    // cout<<u<<" "<<Fa<<" "<<f[u][0]<<" "<<f[u][1]<<"z\n";
}
void vmain(){
    n=read(); m=read(); Ans=0;
    for(int i=1;i<=n;i++) e[i].clear(),vis[i]=0;
    for(int i=1;i<n;i++) {
        eu[i]=read(),ev[i]=read();
        e[eu[i]].psb(ev[i]),e[ev[i]].psb(eu[i]);
    }
    for(int i=1;i<=m;i++) c[i]=read();
    dfs1(1,0);
    for(int i=1;i<n;i++) {
        if(fa[eu[i]]==ev[i]) swap(eu[i],ev[i]);
        bd[ev[i]]=i;
    }
    if(Td==18) {puts("1"); return ;}
    if(Td>=19 && Td<=21){
        Ans=1ll*pw[n-2]*m%P;
        if(n>=3) Ans=(Ans+P-1ll*m*(m-1)/2%P*pw[n-3]%P)%P;
        printf("%d\n",Ans); return ;
    }
    for(int i=1;i<=m;i++){
        int u=eu[c[i]],v=ev[c[i]];
        dfs2(u,v,0); dfs2(v,u,0); vis[c[i]]=1;  Ans=(Ans+1ll*f[u][1]*f[v][1])%P;
    }
    printf("%d\n",Ans); 
}
int main(){
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    pw[0]=1; for(int i=1;i<N;i++) pw[i]=1ll*pw[i-1]*i%P;
    Td=read(); int T=read(); while(T--) vmain();
    return 0;
}
/*
g++ traverse.cpp -o traverse -Wl,-stack=999999999 -Wall -std=c++14
*/