#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;

struct Mouse {
    char color[20];
    int weight;
};

bool compare(Mouse m1, Mouse m2) {
    if (m1.weight - m2.weight >= 0) {
        return true;
    } else {
        return false;
    }

}

Mouse mouse[120];

int main() {
    int N;
    while (scanf("%d", &N) != EOF) {
        for (int i = 0; i < N; i++) {
            scanf("%d %s", &mouse[i].weight, mouse[i].color);
        }
        sort(mouse, mouse + N, compare);
        for (int i = 0; i < N; i++) {
            printf("%s\n", mouse[i].color);
        }
    }
}
// 64 位输出请用 printf("%lld")