#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll i,j,l,m,n,b,f,x,y,co,p,tt,g;
ll s[50008];
ll t[50008];
scanf("%lld",&f);
for( long long int cs=1; cs<=f; cs++)
{
co=0;
map<long long, long long >v;
scanf("%lld",&n);
//g=0;
for(i=0; i<n; i++)
{
scanf("%lld",&s[i]);
scanf("%lld",&t[i]);
//s[g]=x;
//t[g]=y;
//g++;
x=s[i];
y=t[i];
v[x]=y;
}
sort(s,s+n);
// for(i=0;i<n;i++)cout<<s[i]<<endl;
for(i=0; i<n; i++)
{
p=i;
if(s[p]!=-1)
{
co++;
for(j=p+1; j<n; j++)
{
if(s[j]!=-1 ) if(s[j]>v[s[p]])
{
s[j]=-1;
p=j;
}
}
}
}
printf("Case %lld: %lld\n",cs,co);
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwppbnQgbWFpbigpCnsKICAgIGxsIGksaixsLG0sbixiLGYseCx5LGNvLHAsdHQsZzsKICAgIGxsIHNbNTAwMDhdOwogICAgbGwgdFs1MDAwOF07CiAgICBzY2FuZigiJWxsZCIsJmYpOwogICAgZm9yKCBsb25nIGxvbmcgaW50IGNzPTE7IGNzPD1mOyBjcysrKQogICAgewogICAgICAgIGNvPTA7CiAgICAgICAgbWFwPGxvbmcgbG9uZywgbG9uZyBsb25nID52OwogICAgICAgIHNjYW5mKCIlbGxkIiwmbik7CgogICAgICAgIC8vZz0wOwogICAgICAgIGZvcihpPTA7IGk8bjsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgc2NhbmYoIiVsbGQiLCZzW2ldKTsKICAgICAgICAgICAgc2NhbmYoIiVsbGQiLCZ0W2ldKTsKICAgICAgICAgICAgLy9zW2ddPXg7CiAgICAgICAgICAgIC8vdFtnXT15OwogICAgICAgICAgICAvL2crKzsKICAgICAgICAgICAgeD1zW2ldOwogICAgICAgICAgICB5PXRbaV07CiAgICAgICAgICAgIHZbeF09eTsKICAgICAgICB9CiAgICAgICAgc29ydChzLHMrbik7CiAgICAgICAgLy8gZm9yKGk9MDtpPG47aSsrKWNvdXQ8PHNbaV08PGVuZGw7CiAgICAgICAgZm9yKGk9MDsgaTxuOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBwPWk7CgogICAgICAgICAgICBpZihzW3BdIT0tMSkKICAgICAgICAgICAgewoKICAgICAgICAgICAgICAgIGNvKys7CiAgICAgICAgICAgICAgICBmb3Ioaj1wKzE7IGo8bjsgaisrKQogICAgICAgICAgICAgICAgewoKICAgICAgICAgICAgICAgICBpZihzW2pdIT0tMSApIGlmKHNbal0+dltzW3BdXSkKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNbal09LTE7CiAgICAgICAgICAgICAgICAgICAgICAgIHA9ajsKCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBwcmludGYoIkNhc2UgJWxsZDogJWxsZFxuIixjcyxjbyk7CiAgICB9Cn0KCg==