#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
#define mk make_pair
#define all(x) x.begin(), x.end()

template<typename T>void gmax(T &x,T y) { if(x<y) x=y; }
template<typename T>void gmin(T &x,T y) { if(x>y) x=y; }

#ifdef DEBUG
#define debug(x) cerr<<"["<<#x<<"]: "<<x<<endl
#else
#define debug(...) 114
#endif
int c;
const int mod=1e9+7;
void solve() {
    if(c==18) {
        cout<<"1\n";
        return ;
    }
    int n,k; cin>>n>>k;
    vector<vector<pair<int,int>>>e(n+1);
    vector<pair<int,int>>edges;
    bool flag=0,flag1=0;
    for(int i=1,u,v; i<n; i++) cin>>u>>v,e[u].emplace_back(v,i),e[v].emplace_back(u,i),edges.emplace_back(u,v),flag&=u==i&&v==i+1,flag1&=u==1&&v==i;

    vector<int>E(k);
    for(int i=0; i<k; i++) cin>>E[i];
    if(c==19) {
        cout<<n<<'\n';
        return ;
    }
    i64 res=0;
    vector<int>vis(n);
    int from;
    auto dfs=[&](auto &&self,int id) -> void {
        if(vis[id]&&id==from) {
            res++;
            cerr<<endl;
            return ;
        }
        if(vis[id]) return ;
        cerr<<id<<' ';
        vis[id]=1;
        for(auto it:e[edges[id-1].first]) {
            int v=it.first,iD=it.second;
            self(self,iD);
        }
        for(auto it:e[edges[id-1].second]) {
            int v=it.first,iD=it.second;
            self(self,iD);
        }
        vis[id]=0;
    };
    for(int i=0; i<k; i++) {
        from=E[i];
        dfs(dfs,E[i]);
    }
    cout<<res%mod<<'\n';
}
int main() {
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    int t; cin>>c>>t;
    while(t--) solve();
    return 0;
}
