#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct job{
int b;
int j;
bool operator < (const job &x) const {
return j > x.j;
}
};
int main(void)
{
int n, b, j, kase = 1;
while( 1 == scanf("%d", &n) && n){
vector<job> v;
for(int i = 0; i < n; i++){
scanf("%d%d", &b, &j);
v.push_back((job){b, j});
}
sort(v.begin(), v.end());
int s = 0;
int ans = 0;
for(int i = 0; i < n; i++){
s += v[i].b;
ans = max(ans, s + v[i].j);
}
printf("Case %d: %d\n", kase++, ans);
}
return 0;
}
#include <vector>
#include <algorithm>
using namespace std;
struct job{
int b;
int j;
bool operator < (const job &x) const {
return j > x.j;
}
};
int main(void)
{
int n, b, j, kase = 1;
while( 1 == scanf("%d", &n) && n){
vector<job> v;
for(int i = 0; i < n; i++){
scanf("%d%d", &b, &j);
v.push_back((job){b, j});
}
sort(v.begin(), v.end());
int s = 0;
int ans = 0;
for(int i = 0; i < n; i++){
s += v[i].b;
ans = max(ans, s + v[i].j);
}
printf("Case %d: %d\n", kase++, ans);
}
return 0;
}