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

#define ll long long

const int maxn=1e5+5;

struct Edge
{
    int tot;
    int head[maxn];
    struct edgenode{int to,nxt,id;}edge[maxn*2];
    inline void add(int x,int y,int z)
    {
        tot++;
        edge[tot].id=z;
        edge[tot].to=y;
        edge[tot].nxt=head[x];
        head[x]=tot;
    }
}T;
struct EDGE{int u,v;}E[maxn];

ll ans;
ll f[maxn];

int c,n,k;
int ID[maxn];

bool vis[maxn];

inline void work()
{
    ans=0;
    memset(T.head,0,sizeof(T.head));
    memset(vis,0,sizeof(vis));
    T.tot=n=k=0;
}

inline void clr(int id)
{
    vis[id]=0;
    int u=E[id].u;
    for(int i=T.head[u];i;i=T.edge[i].nxt)
    {
        if(vis[T.edge[i].id]&&T.edge[i].id!=ID[1]) clr(T.edge[i].id);
    }
    u=E[id].v;
    for(int i=T.head[u];i;i=T.edge[i].nxt)
    {
        if(vis[T.edge[i].id]&&T.edge[i].id!=ID[1]) clr(T.edge[i].id);
    }
}

inline void solve1(int id)
{
    vis[id]=1;
    int u=E[id].u;
    for(int i=T.head[u];i;i=T.edge[i].nxt)
    {
        if(!vis[T.edge[i].id]) solve1(T.edge[i].id);
        int x=E[id].v;
        bool flg=0;
        for(int j=T.head[x];j;j=T.edge[j].nxt)
        {
            if(vis[T.edge[j].id]) continue;
            flg=1;
            solve1(T.edge[j].id);
            if(id==ID[1]) clr(T.edge[j].id),ans++;
        }
        if(id==ID[1])
        {
            if(!flg) ans++;
            clr(T.edge[i].id);
        }
    }
}

int main()
{
    // freopen("traverse2.in","r",stdin);
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    int _;
    scanf("%d%d",&c,&_);
    if(c==18){while(_--) puts("1");return 0;}
    while(_--)
    {
        work();
        scanf("%d%d",&n,&k);
        for(int i=1;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            T.add(x,y,i);T.add(y,x,i);
            E[i]={x,y};
        }
        for(int i=1;i<=k;i++) scanf("%d",&ID[i]);
        if(c<=3)
        {
            solve1(ID[1]);
            printf("%lld\n",ans);
        }
    }
}