#import <iostream>
inline int redn() {
int ret=0,f=1;char ch=getchar_unlocked();
if(ch == EOF)return-1;
while(ch<'0'||ch>'9'){if(ch=='-') f=-f;ch=getchar_unlocked();}
while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar_unlocked();
return ret*f;
}
int main()
{
int a;
while((a=redn())!=-1){
for(int m=1;m<=a;m++){
std::cout << "Case #" << m << ":\n";
std::string b[10]; int c[10], top=0;
for(int i=0;i<10;i++){
std::cin >> b[i] >> c[i];
}
for(int i=0;i<10;i++)if(top<c[i]) top=c[i];
for(int i=0;i<10;i++)if(c[i]==top) std::cout << b[i]<<"\n";
}
}
}