#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD=1000000007;
int T,n,m,k,c,d[114514],e[114514],x[114514];
map<long long,int>must;
pair<int,int> start[114514];
vector<pair<int,int> >edge[114514];
ll JC[114514];
ll jc(ll x)
{
    if(x==0) return 1;
    if(JC[x]) return JC[x];
    return JC[x]=jc(x-1)*x%MOD;
}
ll dfs(int s,int pre)
{
    if(edge[s].size()==1)
        return 1;
    ll ans=1;
    for(int i=0;i<edge[s].size();i++)
    {
        if(edge[s][i].first!=pre)
        ans*=(dfs(edge[s][i].first,s))%MOD;
        ans%=MOD;
    }
    return ans*(jc(edge[s].size()-1)%MOD);
}

int main()
{
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    cin >> c >> T;
    while(T--)
    {
        cin >> n >>k;
        for(int i=1;i<n;i++)
        {
            int u,v;
            cin >> u>>v;
            edge[u].push_back({v,i});
            edge[v].push_back({u,i});
            start[i]={u,v};
        }
        int s1=0,s2=0;
        for(int i=1;i<=k;i++) cin >> e[i];
        ll ans=0;
        for(int i=1;i<=k;i++)
           ans+=dfs(start[i].first,start[i].second)*
        dfs(start[i].second,start[i].first)%MOD;
        cout<<ans<<endl;
    }

    return 0;
}
