#include<bits/stdc++.h>
using namespace std;
const int N = 1e2+10;
int t,n,m,k,l,r,op,x,y;
string s;
struct nd{
int v;
string n;
bool operator<(const nd&nd1){
return v>nd1.v;
}
};
nd ndd[N];
void solve(){
cin>>n;
for(int i = 1;i<=n;i++){
cin>>ndd[i].v>>ndd[i].n;
}
sort(ndd+1,ndd+1+n);
for(int i = 1;i<=n;i++){
cout<<ndd[i].n<<"\n";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}