#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
const int mod=1e9+7,inv2=500000004;
int fpow(int a,int b=mod-2){
    int r=1;
    while(b){
        if(b&1)r=r*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return r;
}
using namespace std;
int fac[100005],ifac[100005];
int c,T;
int n,k,v[100005];
vector<pii> edges;
int ans;
void ssol1(){
    cout<<1<<'\n';
}
void ssol2(){
    ans=(fac[n-2]-k*fac[n-3]%mod+mod)%mod*k%mod;
    ans=(ans+fac[n-3]*k%mod*(k+1)%mod*inv2%mod)%mod;
    cout<<ans<<'\n';
}
void sol(){
    cin>>n>>k;edges.clear();
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        edges.push_back(pii(u,v));
    }
    for(int i=1;i<=k;i++){
        cin>>v[i];
    }
    if(c==18)ssol1();
    else ssol2();
    return;
}
signed main(){
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for(int i=fac[0]=1;i<=100000;i++)fac[i]=fac[i-1]*i%mod;
    ifac[100000]=fpow(fac[100000]);
    for(int i=99999;i>=0;i--)ifac[i]=ifac[i+1]*(i+1)%mod;
    cin>>c>>T;
    while(T--)sol();
    return 0;
}