#include<bits/stdc++.h>
#define fo(i,x,y) for(int i(x);i<=y;i=-~i)
#define fd(i,x,y) for(int i(x);i>=y;--i)
#define ll long long
#define pb push_back
using namespace std;
char ST;

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

int id,T,n,k,ans,tot,a[N];
vector<int>e[N];
struct edge{
    int x,y;
}b[N];

int read(){
    char ch(getchar());int nu(0),o(0);
    while(ch<48||ch>57){
        if(ch=='-')o=1;ch=getchar();
    }
    while(ch>=48&&ch<=57){
        nu=(nu<<1)+(nu<<3)+(ch^48);ch=getchar();
    }
    if(o)nu=-nu;
    return nu;
}
void upd(int &x,int y){
    x+=y;if(x>=mo)x-=mo;
}
void del(int &x,int y){
    x-=y;if(x<0)x+=mo;
}
int ksm(int x,int y=mo-2){
    int res(1);
    while(y){
        if(y&1)res=1ll*res*x%mo;y>>=1;x=1ll*x*x%mo;
    }
    return res;
}

namespace task1{
    int fac[N],f[N];
    void dp(int x,int pa){
        f[x]=1;
        int cnt(0);
        for(auto y:e[x]){
            if(y==pa)continue;
            dp(y,x);
            f[x]=1ll*f[x]*f[y]%mo;
            ++cnt;
        }
        if(x<=n)f[x]=1ll*f[x]*fac[cnt]%mo;
    }
    void solve(){
        fac[0]=1;fo(i,1,tot)fac[i]=1ll*fac[i-1]*i%mo;
        ans=0;
        fo(i,1,k){
            dp(n+a[i],0);
            upd(ans,f[n+a[i]]);
        }
        printf("%d\n",ans);
    }
}

namespace task2{
    void solve(){
        printf("1\n");
    }
}

namespace task3{
    int fac[N];
    void solve(){
        fac[0]=1;fo(i,1,n)fac[i]=1ll*fac[i-1]*i%mo;
        ans=0;
        upd(ans,1ll*k*fac[n-2]%mo);
        if(k>=2){
            int w=(1ll*k*(k-1)/2)%mo;
            del(ans,1ll*w*fac[n-3]%mo);
        }
        printf("%d\n",ans);
    }
}

void add(int x,int y){
    e[x].pb(y);e[y].pb(x);
}
bool js(){
    fo(i,1,n-1){
        int x(b[i].x),y(b[i].y);
        if(x!=i||y!=i+1)return false;
    }
    return true;
}
bool js2(){
    fo(i,1,n-1){
        int x(b[i].x),y(b[i].y);
        if(x!=1||y!=i+1)return false;
    }
    return true;
}
void solve(){
    n=read();k=read();
    tot=(n<<1)-1;
    fo(i,1,tot)e[i].clear(),e[i].shrink_to_fit();
    fo(i,1,n-1){
        int x(read()),y(read());
        add(x,n+i);add(y,n+i);
        b[i]=(edge){x,y};
    }
    fo(i,1,k)a[i]=read();
    if(js()){
        task2::solve();return;
    }
    if(js2()){
        task3::solve();return;
    }
    task1::solve();
}

char EN;
int main(){
    freopen("traverse.in","r",stdin);freopen("traverse.out","w",stdout);
    // cerr<<(&EN-&ST)/1048576.0<<'\n';
    id=read();T=read();
    while(T--)solve();
    return 0;
}
