#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N=1e5+10;
int n;
struct kk
{
int x;
string color;
bool operator <(const struct kk t)const
{
return x>t.x;
}
}s[N];
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
int x; string color;
cin>>x>>color;
s[i]={x,color};
}
sort(s,s+n);
for(int i=0;i<n;i++)
{
cout<<s[i].color<<endl;
}
}