//类似成绩排序,定义函数更简单一些
#include<iostream>
#include<algorithm>

using namespace std;

struct mouse 
{
    int weight;
    char color[10];
};
bool compare(mouse x,mouse y) 
{
    if(1) 
    {
        return x.weight>y.weight;
    }
}
int main() 
{
    mouse stu[100];
    int n;
    while(scanf("%d",&n)!=EOF) 
    {
        for(int i=0; i<n; i++) 
        {
            scanf("%d %s",&stu[i].weight,&stu[i].color);
        }
        sort(stu,stu+n,compare);
        for(int i=0; i<n; i++) 
        {
            printf("%s\n",stu[i].color);
        }
    }
    return 0;
}