#include <bits/stdc++.h>

using namespace std;

const int K = 1e5+50,N = 1e5+50;
int c,t,n,k,u,v,cru[K];
struct edge{int to,next,bh;}e[2*N],g[200];
int head[N],cnt = 1;
void add(int u,int v,int bh){
    e[++cnt] = {v,head[u],bh},head[u] = cnt;
    e[++cnt] = {u,head[v],bh},head[v] = cnt;
}
int he[200],cn = 1;
void add2(int u,int v){
    g[++cn] = {v,he[u]},he[u] = cn;
    g[++cn] = {u,he[v]},he[v] = cn;
}
int fa[N];
bool vis[N];
void dfs(int u,int fa){
    vis[u] = 1;
    bool tf = 1;
    for (int i = 1;i <= n;i++) if(!vis[i]) tf = 0;
    if(tf){

    }
    for (int i = he[u];i;i = g[i].next){
        int v = g[i].to;
        if(v == fa || vis[v]) continue;
        fa[v] = u;
        dfs(v,u);
    }
}
void init(){

}
int main()
{
    freopen("traverse.in","r",stdin);
    freopen("traverse.out","w",stdout);
    scanf("%d%d",&c,&t);
    while(t--){
        init();
        scanf("%d%d",&n,&k);
        for (int i = 1;i < n;i++){
            scanf("%d%d",&u,&v);
            for (int j = head[u];j;j = e[j].next){
                add2(i,e[j].bh);
            }
            for (int j = head[v];j;j = e[j].next){
                add2(i,e[j].bh);
            }
            add(u,v,i);
        }
        for (int i = 1;i <= k;i++){
            scanf("%d",&cru[i]);
        }
        if(n <= 5 && k == 1){
            dfs(cru[1],0);
        }
        if(c == 18){
            printf("1\n");
            continue;
        }
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}

