#include<bits/stdc++.h>
using namespace std;

int main() {
    map<int,string> m;//使用map存储数据,每只小鼠的信息构成一个键值对
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int weight;
        string color;
        cin >> weight >> color;
        m.insert(make_pair(weight,color));
    }
    for (auto iter = m.rbegin(); iter != m.rend(); iter++) {//使用迭代器反向遍历map
        cout << iter->second << endl;
    }
}

map默认按照key从小到大排序