#include <stdio.h>
struct book{
    char name[20];
    float price;
};

int main() {
    int n;
    scanf("%d", &n);
    struct book b[n];
    for(int i = 0; i < n; i++){
        scanf("%s %f", b[i].name, &b[i].price);
    }

    // 选择排序
    for(int i = 0; i<n; i++){
        int min = i;
        for(int j = i; j<n; j++){
            if(b[j].price < b[min].price)
                min = j;
        }
        printf("%s\n", b[min].name);
        struct book t = b[i];
        b[i] = b[min];
        b[min] = t;
    }
    return 0;
}