#include<bits/stdc++.h>
#define ll long long
// #define int long long
#define pii pair<int,int>
using namespace std;
const int N=1e6+7;
const ll P=1e9+7;
ll ans;
int c,T,n,k,u[N],v[N],x;
vector<int>edge[N];
map<pii,bool> mp;
void add(int u,int v){
   edge[u].push_back(v);
}
ll dfs(int x,int fa){
    mp[{x,fa}]=1;
    int deg=0;ll ans=1,tmp;
    for(int i:edge[x]){
        if(i==fa||mp[{i,x}]) continue;
        deg++,tmp=dfs(i,x);
        if(tmp) ans=ans*tmp%P;
    }
    if(deg) ans=ans*deg%P;
    return ans;
}
signed main(){
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    scanf("%d%d",&c,&T);
    while(T--){
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++) edge[i].clear();
        for(int i=1;i<n;i++)
            scanf("%d%d",&u[i],&v[i]),add(u[i],v[i]),add(v[i],u[i]);
        ans=0;
        for(int i=1;i<=k;i++)
            scanf("%d",&x),ans+=(dfs(u[x],v[x])*dfs(v[x],u[x]))%P,ans%=P;
        printf("%lld\n",ans);
    }
}