import java.util.Scanner;
import java.util.ArrayList;
public class Main
{
static ArrayList
<Integer
>g
[]=new ArrayList[20005]; static boolean vis[]=new boolean[20005];
static int xx,yy;
static void dfs(int source, boolean 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].get(i),!p);
return;
}
public static void main
(String[] args
) {
for (int i=0; i<20005; i++)
g[i] = new ArrayList<>();
Scanner s
=new Scanner
(System.
in); int t,n,a,b;
t=s.nextInt();
for(int i=1;i<=t;i++)
{
for(int j=0;j<20005;j++)
g[j].clear();
for(int j=0;j<20005;j++)
vis[j]=false;
n=s.nextInt();
for(int j=1;j<=n;j++)
{
a=s.nextInt();
b=s.nextInt();
g[a].add(b);
g[b].add(a);
}
int ans=0;
for(int j=1;j<20005;j++)
if(vis[j]==false && !g[j].isEmpty())
{
xx=yy=0;
dfs(j,true);
}
System.
out.
println("Case "+i
+": "+ans
); }
s.close();
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwppbXBvcnQgamF2YS51dGlsLkFycmF5TGlzdDsKIApwdWJsaWMgY2xhc3MgTWFpbgp7CiAgICBzdGF0aWMgQXJyYXlMaXN0PEludGVnZXI+Z1tdPW5ldyBBcnJheUxpc3RbMjAwMDVdOwogICAgc3RhdGljIGJvb2xlYW4gdmlzW109bmV3IGJvb2xlYW5bMjAwMDVdOwogICAgc3RhdGljIGludCB4eCx5eTsKICAgCiAgICBzdGF0aWMgdm9pZCBkZnMoaW50IHNvdXJjZSwgYm9vbGVhbiBwKQogICAgewogICAgICAgIGlmKHZpc1tzb3VyY2VdPT10cnVlKQogICAgICAgIHJldHVybjsKICAgICAgICB2aXNbc291cmNlXT10cnVlOwogICAgICAgIGlmKHApCiAgICAgICAgeHgrKzsKICAgICAgICBlbHNlCiAgICAgICAgeXkrKzsKICAgICAgICBpbnQgc3o9Z1tzb3VyY2VdLnNpemUoKTsKICAgICAgICBmb3IoaW50IGk9MDtpPHN6O2krKykKICAgICAgICBkZnMoZ1tzb3VyY2VdLmdldChpKSwhcCk7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpCiAgICB7CiAgICAgICAgZm9yIChpbnQgaT0wOyBpPDIwMDA1OyBpKyspCiAgICAgICAgICAgIGdbaV0gPSBuZXcgQXJyYXlMaXN0PD4oKTsKICAgICAgIAogICAgICAgIFNjYW5uZXIgcz1uZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwogICAgICAgIGludCB0LG4sYSxiOwogICAgICAgIHQ9cy5uZXh0SW50KCk7CiAgICAgICAgZm9yKGludCBpPTE7aTw9dDtpKyspCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGo9MDtqPDIwMDA1O2orKykKICAgICAgICAgICAgICAgIGdbal0uY2xlYXIoKTsKICAgICAgICAgICAKICAgICAgICAgICAgZm9yKGludCBqPTA7ajwyMDAwNTtqKyspCiAgICAgICAgICAgICAgICB2aXNbal09ZmFsc2U7CiAgICAgICAgICAgCiAgICAgICAgICAgIG49cy5uZXh0SW50KCk7CiAgICAgICAgICAgCiAgICAgICAgICAgIGZvcihpbnQgaj0xO2o8PW47aisrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBhPXMubmV4dEludCgpOwogICAgICAgICAgICAgICAgYj1zLm5leHRJbnQoKTsKICAgICAgICAgICAgICAgIGdbYV0uYWRkKGIpOwogICAgICAgICAgICAgICAgZ1tiXS5hZGQoYSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAKICAgICAgICAgICAgaW50IGFucz0wOwogICAgICAgICAgICBmb3IoaW50IGo9MTtqPDIwMDA1O2orKykKICAgICAgICAgICAgaWYodmlzW2pdPT1mYWxzZSAmJiAhZ1tqXS5pc0VtcHR5KCkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB4eD15eT0wOwogICAgICAgICAgICAgICAgICAgIGRmcyhqLHRydWUpOwogICAgICAgICAgICAgICAgICAgIGFucys9TWF0aC5tYXgoeHgseXkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQ2FzZSAiK2krIjogIithbnMpOwogICAgICAgICAgICBTeXN0ZW0uZ2MoKTsKICAgICAgICB9CiAgICAgICAgU3lzdGVtLmdjKCk7CiAgICAgICAgcy5jbG9zZSgpOwogICAgfQp9