#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstring>
#include<set>
using namespace std;
struct node1
{
int x,y;
int pos,f;
friend bool operator <(node1 a,node1 b)
{
return a.pos<b.pos;
}
}p[5005];
bool cmp(node1 a,node1 b)
{
return a.pos<b.pos;
}
struct node
{
int l,r;
long long maxn;
//long long v;
int f;
} tree[50005*5];
node up(node cur, node x,node y)
{
node ntree;
ntree.maxn=max(x.maxn,y.maxn);
ntree.l=x.l;
ntree.r=y.r;
ntree.f=cur.f;
return ntree;
}
void down(int i)
{
if(tree[i].f!=0)
{
tree[i*2].f+=tree[i].f;
tree[i*2+1].f+=tree[i].f;
tree[i*2].maxn+=tree[i].f;
tree[i*2+1].maxn+=tree[i].f;
tree[i].f=0;
}
return ;
}
void build(int i,int l,int r)
{
tree[i].l=l;
tree[i].r=r;
tree[i].f=0;
tree[i].maxn=0;
if(l==r)
{
//tree[i].v=0;
tree[i].maxn=0;
return ;
}
else
{
int mid=(l+r)/2;
build(i*2,l,mid);
build(i*2+1,mid+1,r);
tree[i]=up(tree[i],tree[i*2],tree[2*i+1]);
}
}
void updata(int i,int l,int r,long long v)
{
if(tree[i].l==l&&tree[i].r==r)
{
tree[i].maxn=v;
return ;
}
int mid=(tree[i].l+tree[i].r)/2;
down(i);
if(r<=mid)
{
updata(i*2,l,r,v);
}
else if(l>mid)
updata(i*2+1,l,r,v);
else
{
updata(i*2,l,mid,v);
updata(i*2+1,mid+1,r,v);
}
tree[i]=up(tree[i],tree[i*2],tree[2*i+1]);
}
void updata1(int i,int l,int r,long long v)
{
if(tree[i].l==l&&tree[i].r==r)
{
tree[i].maxn+=v;
tree[i].f+=v;
return ;
}
int mid=(tree[i].l+tree[i].r)/2;
down(i);
if(r<=mid)
{
updata1(i*2,l,r,v);
}
else if(l>mid)
updata1(i*2+1,l,r,v);
else
{
updata1(i*2,l,mid,v);
updata1(i*2+1,mid+1,r,v);
}
tree[i]=up(tree[i],tree[i*2],tree[2*i+1]);
}
node get(int i,int l,int r)
{
if(tree[i].l==l&&tree[i].r==r)
{
return tree[i];
}
down(i);
int mid=(tree[i].l+tree[i].r)/2;
if(r<=mid)
return get(i*2,l,r);
else if(l>mid)
return get(i*2+1,l,r);
else
{
node c;
node a=get(i*2,l,mid);
node b=get(i*2+1,mid+1,r);
return up(c,a,b);
}
}
int s[2005];
int main()
{
int t;
scanf("%d",&t);
int cas=0;
while(t--)
{
cas++;
int n;
scanf("%d",&n);
int cnt=0;
for(int i=0;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
y++;
p[cnt].x=x;
p[cnt].y=y;
p[cnt].pos=x;
p[cnt].f=1;
cnt++;
p[cnt].x=x;
p[cnt].y=y;
p[cnt].pos=y;
p[cnt].f=-1;
cnt++;
}
sort(p,p+cnt,cmp);
int ans=0;
int curc=0;
build(1,1,cnt);
for(int i=0;i<cnt;i++)
{
if(p[i].f==1)
{
curc++;
int maxn;
if(i!=0)
maxn=get(1,1,i).maxn;
else
maxn=0;
updata(1,i+1,i+1,maxn);
if(curc>=3)
ans=max(ans,maxn+curc);
s[i]=curc;
}
else
{
curc--;
int pre=p[i].x;
node1 tp;
tp.pos=pre;
int preid=lower_bound(p,p+cnt,tp)-p;
//cout<<preid<<endl;
updata1(1,preid+1,i,1);
int maxn=get(1,1,i).maxn;
updata(1,i+1,i+1,maxn);
if(curc>=3)
ans=max(ans,maxn+curc);
s[i]=curc;
}
}
printf("Case #%d: ",cas);
printf("%d\n",ans);
}
}