#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
typedef struct mo{
int weigh;
string col;
}Mo;
bool cmp(Mo m1,Mo m2)
{
return m1.weigh>=m2.weigh;
}
Mo m[110];
int main() {
int N;
cin>>N;
for(int i=1;i<=N;i++)
{
cin>>m[i].weigh;
cin>>m[i].col;
}
sort(m+1,m+N+1,cmp);
for(int i=1;i<=N;i++)
{
cout<<m[i].col<<endl;
}
}
// 64 位输出请用 printf("%lld")

京公网安备 11010502036488号