#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_NUM = 100;
//结构体保存小白鼠信息
struct Mouse {
int weight;
string color;
};
bool compareAscend(Mouse x, Mouse y) {
//按体重降序排序
return x.weight > y.weight;
}
/**
* 小白鼠排队
* @return
*/
int main() {
Mouse mouse[MAX_NUM];
int n;
while (cin >> n) {
for (int i = 0; i < n; ++i) {
cin >> mouse[i].weight >> mouse[i].color;
}
sort(mouse, mouse + n, compareAscend);
for (int i = 0; i < n; ++i) {
cout << mouse[i].color << endl;
}
}
return 0;
}