#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(){
int n;
cin >> n;
int c = 1;
for(int i = 0; i < n; i++){
queue <string> q = queue <string>();
bool first = true;
int number;
int max = 0;
string url;
for(int i = 1; i <= 10; i++){
cin >> url >> number;
if (number > max){
q = queue<string>();
max = number;
q.push(url);
} else if (max == number){
q.push(url);
}
}
cout << "Case #" << c << ":" << endl;
c++;
while(!q.empty()){
string a = q.front();
q.pop();
cout << a << endl;
}
}
return 0;
}