#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define fi first
#define se second
#define pa pair <int, int>
int cases = 0;
vector <pa> a;
bool comp(const pa & a,const pa & b){
return (a.se > b.se || (a.fi < b.fi && a.se == b.se));
}
int n;
inline int getint(){
char ch;
int x = 0;
while (!isdigit(ch = getchar()));
x = ch - 48;
while (isdigit(ch = getchar())) x = x * 10 + ch - 48;
return x;
}
int main(){
freopen("commando.in","r",stdin);
freopen("commando.out","w",stdout);
while (n = getint(),n){
printf("Case %d: ",++cases);
a.clear();
int x,y;
int ans = 0;
for (int i = 1; i <= n; i++){
x = getint(); y = getint();
a.push_back(make_pair(x,y));
ans += x;
}
sort(a.begin(),a.end(),comp);
int s = 0;
for (int i = 0; i < n; i++){
s += a.at(i).fi;
ans = max(ans,s + a.at(i).se);
}
printf("%d\n",ans);
}
return 0;
}