#include <iostream>
#include <algorithm>
using namespace std;
struct mouse{
int w;
string hcolor;
};
bool CompM(mouse m1, mouse m2){
return m1.w>m2.w;
}
int main() {
int n;
while (cin>>n){
mouse mice[n];
for(int i=0;i<n;i++){
cin>>mice[i].w>>mice[i].hcolor;
}
sort(mice,mice+n,CompM);
for(int i=0;i<n;i++){
cout<<mice[i].hcolor<<endl;
}
}
}

京公网安备 11010502036488号