#include<stdio.h>
struct Case{
char str[101];
int relative;
}ccase[10];
int main(){
int num;
scanf("%d", &num);
for(int i = 1; i <= num; ++i){
for(int j = 0; j < 10; ++j){
scanf("%s", &ccase[j].str);
scanf("%d", &ccase[j].relative);
}
int max = 0;
for(int j = 0; j < 10; ++j)
if(max < ccase[j].relative)
max = ccase[j].relative;
printf("Case #%d:\n", i);
for(int j = 0; j < 10; ++j)
if(ccase[j].relative == max)
printf("%s\n", ccase[j].str);
}
return 0;
}