#include<stdio.h>
typedef struct mouse{ int weight; char color[10]; }mouse;
int cmp(const voida,const voidb){ return ((mouse)a).weight<((mouse)b).weight; }
int main (){ int n=0; mouse m[100]; scanf("%d",&n); for (int i=0;i<n;i++){ scanf("%d%s",&m[i].weight,&m[i].color); } qsort(m,n,sizeof(mouse),cmp); for (int i=0;i<n;i++){ printf("%s\n",m[i].color); } return 0; }