#include <stdio.h>
#include <stdlib.h>
typedef struct{
int weight;
char head[11];
} mouse;
int cmp(const void *a,const void *b){
mouse*a1=(mouse*)a;
mouse*b1=(mouse*)b;
return b1->weight-a1->weight;
}
int main() {
int n;
while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case
mouse mouse1[n];
for(int i=0;i<n;i++){
scanf("%d %s",&mouse1[i].weight,mouse1[i].head);
}
qsort(mouse1,n,sizeof(mouse), cmp);
for (int i=0; i<n; i++) {
printf("%s\n",mouse1[i].head);
}
}
return 0;
}



京公网安备 11010502036488号