#include<iostream>
#include<algorithm>
using namespace std;
struct rat{
int weight;
char color[20];
bool operator < (rat stu){ //小于号运算符重载
return weight>stu.weight;
}
};
rat ss[101];
int main(){
int n;
while(cin>>n){
for(int i=0;i<n;i++){
cin>>ss[i].weight>>ss[i].color;
}
sort(ss,ss+n);
for(int i=0;i<n;i++){
cout<<ss[i].color<<endl;
}
}
return 0;
}
#include<algorithm>
using namespace std;
struct rat{
int weight;
char color[20];
bool operator < (rat stu){ //小于号运算符重载
return weight>stu.weight;
}
};
rat ss[101];
int main(){
int n;
while(cin>>n){
for(int i=0;i<n;i++){
cin>>ss[i].weight>>ss[i].color;
}
sort(ss,ss+n);
for(int i=0;i<n;i++){
cout<<ss[i].color<<endl;
}
}
return 0;
}