#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
struct Mouse {
    int weight;
    char color[10];
};
bool compp(Mouse x, Mouse y) {
    return x.weight >
           y.weight; //按照白鼠的重量从大到小的顺序输出白鼠的帽子颜
}
int main() {
    Mouse mouse[101];
    int n, i;
    while (scanf("%d", &n) != EOF) {
        for (i = 0; i < n; i++) {
            cin >> mouse[i].weight >> mouse[i].color;
        }
        sort(mouse, mouse + n,
             compp); //按照白鼠的重量从大到小的顺序输出白鼠的帽子颜
        //此时,数据中时=是已经排列好的鼠鼠,现在要输出最肥的鼠的帽子颜色
        for (i = 0; i < n; i++) {
            cout << mouse[i].color << endl;
        }

    }


    return 0;
}