#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t,n,c,e[100005],k;
ll fac[100005];
ll tot,son[200005],nxt[200005],head[200005];
ll num[200005];
ll dp[200005];
bool vis[200005];
const ll mod=1e9+7;
struct inttt{
    ll x,y;
}edge[100005];
void link(ll x,ll y,ll tmp){
    tot++;
    son[tot]=y;
    nxt[tot]=head[x];
    head[x]=tot;
    num[tot]=tmp;
}
ll qpow(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1) (res*=x)%=mod;
        (x*=x)%=mod;
        y>>=1;
    }
    return res;
}
int read(){
    char c=getchar();int x=0;
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
    return x;
}
void dfs(ll pos,ll fa,bool flag){
    ll siz=0,sizk=0;
    dp[pos]=1;
    for(int i=head[pos];i;i=nxt[i]){
        ll v=son[i];
        if(v==fa) continue;
        if(vis[num[i]]) sizk++;
        dfs(v,pos,vis[num[i]]);
        siz++;
        dp[pos]=dp[pos]*dp[v]%mod;
    }
    ll tmp=dp[pos];
    if(!sizk||siz<2||!flag) dp[pos]=dp[pos]*fac[siz]%mod;
    else dp[pos]=(dp[pos]*sizk%mod*fac[siz-1]%mod-sizk*(sizk-1)%mod*fac[siz-2]%mod+dp[pos]*fac[siz]%mod+mod)%mod;
}
int main(){
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    scanf("%lld%lld",&c,&t);
    while(t--){
        tot=0;
        memset(head,0,sizeof(head));
        memset(dp,0,sizeof(dp));
        memset(nxt,0,sizeof(nxt));
        memset(vis,0,sizeof(vis));
        scanf("%lld%lld",&n,&k);
        ll lst=0;        
        for(int i=1;i<n;i++){
            ll x,y;
            x=read(),y=read();
            link(x,y,i);
            link(y,x,i);
            edge[i].x=x;
            edge[i].y=y;
        }
        for(int i=1;i<=k;i++){
            e[i]=read();
            vis[e[i]]=true;
        }
        if(n==2){
            printf("1\n");
            continue;
        }

        if(c==18){
            printf("1\n");
            continue;
        }            
        fac[0]=1;
        for(int i=lst+1;i<=n;i++){
            fac[i]=fac[i-1]*i%mod;
        }
        lst=max(lst,n);
        if(c>=19&&c<=21){

            printf("%lld\n",(k*fac[n-2]%mod-k*(k-1)%mod*fac[n-3]%mod*qpow(2,mod-2)%mod+mod)%mod);
            continue;
        }
        dfs(edge[e[1]].x,edge[e[1]].y,true);
        dfs(edge[e[1]].y,edge[e[1]].x,true);
        printf("%lld\n",dp[edge[e[1]].x]*dp[edge[e[1]].y]%mod);
    }
    return 0;
}
