#include<bits/stdc++.h>
using namespace std;
vector<vector<int> >g(20005);
bool vis[20005];
int xx,yy,a,b,n,t;
void dfs(int source, bool p)
{
if(vis[source]==true)
return;
vis[source]=true;
if(p)
xx++;
else
yy++;
int sz=g[source].size();
for(int i=0;i<sz;i++)
dfs(g[source][i],!p);
return;
}
int main()
{
cin>>t;
for(int i=1;i<=t;i++)
{
memset(vis,false,sizeof vis);
for(int j=0;j<=20004;j++)
g[j].clear();
cin>>n;
for(int j=1;j<=n;j++)
{
scanf("%d%d",&a,&b);
g[a].push_back(b);
g[b].push_back(a);
}
int ans=0;
for(int j=1;j<=20003;j++)
if(vis[j]==false && g[j].size()>0)
{
xx=yy=0;
dfs(j,true);
ans+=max(xx,yy);
}
cout<<"Case "<<i<<": "<<ans<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZlY3Rvcjx2ZWN0b3I8aW50PiA+ZygyMDAwNSk7CmJvb2wgdmlzWzIwMDA1XTsKCmludCB4eCx5eSxhLGIsbix0OwoKdm9pZCBkZnMoaW50IHNvdXJjZSwgYm9vbCBwKQp7CiAgICBpZih2aXNbc291cmNlXT09dHJ1ZSkKICAgIHJldHVybjsKICAgIHZpc1tzb3VyY2VdPXRydWU7CiAgICBpZihwKQogICAgeHgrKzsKICAgIGVsc2UKICAgIHl5Kys7CiAgICBpbnQgc3o9Z1tzb3VyY2VdLnNpemUoKTsKICAgIGZvcihpbnQgaT0wO2k8c3o7aSsrKQogICAgZGZzKGdbc291cmNlXVtpXSwhcCk7CiAgICByZXR1cm47Cn0KCmludCBtYWluKCkKewogICAgY2luPj50OwogICAgZm9yKGludCBpPTE7aTw9dDtpKyspCiAgICB7CiAgICAgICAgbWVtc2V0KHZpcyxmYWxzZSxzaXplb2YgdmlzKTsKICAgICAgICBmb3IoaW50IGo9MDtqPD0yMDAwNDtqKyspCiAgICAgICAgZ1tqXS5jbGVhcigpOwoKICAgICAgICBjaW4+Pm47CiAgICAgICAgZm9yKGludCBqPTE7ajw9bjtqKyspCiAgICAgICAgewogICAgICAgICAgICBzY2FuZigiJWQlZCIsJmEsJmIpOwogICAgICAgICAgICBnW2FdLnB1c2hfYmFjayhiKTsKICAgICAgICAgICAgZ1tiXS5wdXNoX2JhY2soYSk7CiAgICAgICAgfQogICAgICAgIGludCBhbnM9MDsKICAgICAgICBmb3IoaW50IGo9MTtqPD0yMDAwMztqKyspCiAgICAgICAgaWYodmlzW2pdPT1mYWxzZSAmJiBnW2pdLnNpemUoKT4wKQogICAgICAgIHsKICAgICAgICAgICAgeHg9eXk9MDsKICAgICAgICAgICAgZGZzKGosdHJ1ZSk7CiAgICAgICAgICAgIGFucys9bWF4KHh4LHl5KTsKICAgICAgICB9CiAgICAgICAgY291dDw8IkNhc2UgIjw8aTw8IjogIjw8YW5zPDxlbmRsOwogICAgfQogICAgcmV0dXJuIDA7Cn0K