#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Rat
{
int weight;
char color[10];
};
void swap(struct Rat *x,struct Rat *y)
{
int w=x->weight;
x->weight=y->weight;
y->weight=w;
char ch[10];
strcpy(ch,x->color);
strcpy(x->color,y->color);
strcpy(y->color,ch);
}
void bubbleSort(struct Rat *p , int n)
{
int i,j;
for(i=n-1;i>-1;i--)
for(j=0;j<i;j++)
if(p[j].weight>p[j+1].weight)
swap(&p[j],&p[j+1]);
}
int main()
{
int n,i;
scanf("%d",&n);
struct Rat *rat=(struct Rat*)malloc(sizeof(struct Rat)*n);
for(i=0;i<n;i++)
scanf("%d %s",& rat[i].weight, rat[i].color);
bubbleSort(rat,n);
for(i=0;i<n;i++)
printf("%s\n",rat[i].color);
return 0;
}