#include <iostream>
using namespace std;
struct website {
char url[100];
int relation;
};
int main()
{
int i;
while (cin >> i)
{
website input[10];
int highest = 0;
for (int k = 0 ; k < i; k++)
{
for (int r = 0 ; r < 10 ; r++)
{
getline(cin, input[r].url);
cin >> input[r].relation;
}
for (int r = 0 ; r < 10 ; r++)
if (input[r].relation > highest) highest = input[r].relation;
cout << "Case #" << k+1 << ":" << endl;
for (int r = 0 ; r < 10 ; r++)
if (input[r].relation == highest) cout << input[r].url << endl;
}
}
}