#include <iostream>
#include <algorithm>
using namespace std;

struct S{
	int b;
	int j;
};

bool compare(const S &a, const S &b){
	int t1 = 0, t2 = 0;
	t1 = a.b + max(a.j, b.b + b.j);
	t2 = b.b + max(b.j, a.b + a.j);
	return t1 < t2;
}

S s[1001];

int main(){
	int n, C = 1;
	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++)
			scanf("%d %d", &s[i].b, &s[i].j);
		sort(s, s+n, compare);
		
		int t = 0, t2 = 0;
		for (int i = 0; i < n; i++){
			t += s[i].b;
			t2 = max(t2, t + s[i].j);
		}
		printf("Case %d: %d\n", C++, t2);
	}
	return 0;
}
