#include <stdio.h>
#define MAXSIZE 30
typedef struct
{
    int n;
    char a[MAXSIZE];
} Mouse;
int main() {
    int count;
    scanf("%d", &count);
    int m = count;
    int p = count;
    Mouse M[count];
    for (int i = 0; i < count; i++) {
        scanf("%d %s", &M[i].n, M[i].a);
    }
    while (m--) { // 降序
        for (int j = 0; j < m; j++) {
            if (M[j].n < M[j + 1].n) {
                Mouse T = M[j + 1];
                M[j + 1] = M[j];
                M[j] = T;
            }
        }
    }
    for (int j = 0; j < p; j++) {
        printf("%s\n", M[j].a);
    }
    return 0;
}