#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
vector <int> V[maxn];
struct Node{
int node;
int father;
int deep;
Node(){
node = father = deep = 0;
}
}N[maxn],Un[maxn];
int child[maxn];
bool vis[maxn];
int change[maxn];
void dfs(int n){
int len = V[n].size();
vis[n] = true;
for(int i=0;i<len;i++){
if(!vis[V[n][i]]){
++child[n];
N[V[n][i]].father = n;
N[V[n][i]].deep = N[n].deep+1;
dfs(V[n][i]);
}
}
}
int cmp(const Node &A,const Node &B){
return A.deep > B.deep;
}
int main()
{
ios::sync_with_stdio(false);
int T,cnt=0;
cin>>T;
while(T--){
for(int i=0;i<maxn;i++) V[i].clear();
memset(child,0,sizeof(child));
memset(vis,false,sizeof(vis));
int n,q;
cin>>n>>q;
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
V[u].push_back(v);
V[v].push_back(u);
}
N[1].deep=1;
N[1].father=-1; //表示是根节点
dfs(1);
int Count;
cout<<"Case #"<<++cnt<<":\n";
for(int i=0;i<q;i++){
Count = 0;
int m;
cin>>m;
for(int j=0;j<m;j++){
int node;
cin>>node;
Un[j].deep = N[node].deep;
Un[j].father = N[node].father;
Un[j].node = node;
}
sort(Un,Un+m,cmp);
int ans = n-m;
for(int j=0;j<m;j++){
if( child[ Un[j].node ] >= 2 ) ++ans;
else if( child[ Un[j].node ] == 0 ) {
change[Count++] = Un[j].father;
--child[ Un[j].father ];
}
}
for(int j=0;j<Count;j++){
++child[ change[j] ];
}
cout<<ans<<endl;
}
}
return 0;
}
08-10
08-10
07-18