#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define fi first
#define se second
using namespace std; using pii = pair<int,int>;
const int N=1e5+5,mod=1e9+7;
class Int{
    int x;
public:
    explicit Int(int _x=0) : x(_x) {}
    Int& operator+= (Int O) { x=(x+O.x)%mod; return *this; }
    Int& operator-= (Int O) { x=(x-O.x+mod)%mod; return *this; }
    Int& operator*= (Int O) { x=1ll*x*O.x%mod; return *this; }
    friend Int operator+ (Int A,Int B) { return A+=B; }
    friend Int operator- (Int A,Int B) { return A-=B; }
    friend Int operator* (Int A,Int B) { return A*=B; }
    int operator() () const { return x; }
};
int n,m,vis[N]; vector<pii> to[N]; Int f[N][2][2];
void dfs(int u,int pa){
    if(to[u].size()==1u){
        f[u][1][0]=Int(1); return;
    }
    Int g[3][2]; g[0][0]=Int(1);
    for(auto [v,e]:to[u]) if(v!=pa){
        dfs(v,u); Int h[3][2]; int o=vis[e];
        For(x,0,1) For(y,0,1){
            h[1][x|y]   += g[0][x]*f[v][0][y];
            h[2][x|y]   += g[1][x]*f[v][0][y];
            h[0][x|y]   += g[0][x]*f[v][1][y];
            h[1][x|y]   += g[1][x]*f[v][1][y];
            h[2][x|y]   += g[2][x]*f[v][1][y];
            h[1][x|y|o] += g[0][x]*f[v][1][y];
            h[2][x|y|o] += g[1][x]*f[v][1][y];
        }
        For(x,0,2) For(y,0,1) g[x][y]=h[x][y];
    }
    For(x,0,1){
        f[u][0][x]=g[2][x];
        f[u][1][x]=g[1][x];
    }
}
void Mian(){
    cin>>n>>m; For(i,0,n) { to[i].clear(),vis[i]=0; For(x,0,1) For(y,0,1) f[i][x][y]=Int(0); }
    For(i,1,n-1) { int x,y; cin>>x>>y; to[x].emplace_back(y,i); to[y].emplace_back(x,i); }
    For(i,1,m) { int x; cin>>x; vis[x]=1; }
    int rt=0; For(i,1,n) if(to[i].size()>1u) { rt=i; break; }
    if(rt==0) { cout<<"1\n"; return; }
    dfs(rt,0); Int ans=f[rt][0][1]; //cerr<<"ans="<<ans()<<'\n';
    static Int cp[N]; cp[0]=Int(1); For(i,1,n) cp[i]=cp[i-1]*Int(i);
    For(i,1,n) { int x=to[i].size(); if(x>2) ans*=cp[x-2]; }
    cout<<ans()<<'\n';
}
namespace HEY{
    int n,m,a[N],b[N],vis[N],fa[N]; set<set<pii>> S; set<pii> s; vector<int> lis[N],to[N];
    void dfs(int u,int dir){
        vis[u]=1; if(s.size()==n-2u) { S.insert(s); vis[u]=0; return; }
        int qwq=1;
        for(int v:to[u]) if(!vis[v]){
            qwq=0; s.insert(minmax(u,v)); assert(fa[u]!=v); fa[v]=u; dfs(v,0); s.erase(minmax(u,v)); fa[v]=0; assert(vis[u]);
        }
        if(qwq&&fa[u]) dfs(fa[u],1);
        if(dir==0) vis[u]=0;
    }
    void Mian(){
        cin>>n>>m; For(i,0,n) to[i].clear(),lis[i].clear();
        For(u,1,n-1){
            int x,y; cin>>x>>y;
            for(int v:lis[x]) to[u].push_back(v),to[v].push_back(u);
            for(int v:lis[y]) to[u].push_back(v),to[v].push_back(u);
            lis[x].push_back(u); lis[y].push_back(u);
        }
        // For(u,1,n) for(int v:to[u]) if(u<v) cerr<<u<<' '<<v<<'\n';
        S.clear();
        while(m--) { int e; cin>>e; dfs(e,0); }
        cout<<S.size()<<'\n';
    }
}
int main(){
    Fin("traverse.in"); Fout("traverse.out");
    ios::sync_with_stdio(0); cin.tie(0);
    int Charlie,Ti; cin>>Charlie>>Ti;
    if(Charlie>=1&&Charlie<=3){
        HEY::Mian();
    }
    else{
        while(Ti--) Mian();
    }
    return 0;
}