#include <bits/stdc++.h>

#define int long long

using namespace std;

#define fileio(x,y) freopen(x,"r",stdin),freopen(y,"w",stdout)
#define tup tuple<int,int,int>
#define pii pair<int,int>
#define pb emplace_back
#define i12 __int128_t
#define mt make_tuple
#define mp make_pair

const int   maxn=1e5+10;
const int   mod=1e9+7;

// char nc() { static char buf[1<<20],*p1=buf,*p2=buf; return (p2==p1&&(p2=(p1=buf)+fread(buf,1,1<<17,stdin),p2==p1)? EOF:*p1++); }
// int read() { int x=0,f=1; char c=nc(); while(!isdigit(c)) { if(c=='-') f=-1; c=nc(); } while(isdigit(c)) x=x*10+c-'0',c=nc(); return x*f; }

vector<int> road[maxn];
pii         a[maxn];
int         f[maxn],g[maxn];
int         n,k;

int dfs(int root,int fa)
{
    // cerr<<"dfs "<<root<<' '<<fa<<'\n';
    g[root]=1;
    int ch=0;
    for(int it:road[root])
    {
        if(it==fa) continue;
        dfs(it,root); ch++;
        (g[root]*=g[it])%=mod;
    }
    (g[root]*=f[ch])%=mod;
    return ch;
}

void work()
{
    /* Code */
    // n=read(),k=read();
    cin>>n>>k;
    for(int i=1; i<=n; i++) road[i].clear();
    // for(int i=1,x,y; i<n; i++) x=read(),y=read(),a[i]=mp(x,y),road[x].pb(y),road[y].pb(x);
    for(int i=1,x,y; i<n; i++) cin>>x>>y,a[i]=mp(x,y),road[x].pb(y),road[y].pb(x);
    // cerr<<"OKOK"<<'\n';
    int res=0;
    for(int i=1,x; i<=k; i++)
    {
        cin>>x; int temp=1;
        int t1=dfs(a[i].first,a[i].second);
        (temp*=g[a[i].first])%=mod;
        int t2=dfs(a[i].second,a[i].first);
        (temp*=g[a[i].second])%=mod;
        // cerr<<t1<<' '<<t2<<'\n';
        // (temp*=(!!t1+!!t2))%=mod;
        res+=temp;
    }
    cout<<res<<'\n';
    return;
}

signed main()
{
    fileio("traverse.in","traverse.out");
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tid,t,stTime=clock();
    // tid=read(),t=read();
    cin>>tid>>t;
    f[0]=1; for(int i=1; i<maxn; i++) f[i]=((i-1)*f[i-1]%mod+1)%mod;
    while(t--) work();
    // cerr<<"Time : "<<(double)(clock()-stTime)/CLOCKS_PER_SEC<<'\n';
    return 0;
}