#include <bits/stdc++.h>
using namespace std;
struct rank {
string id;
double cj;
};
rank st[1001];
bool cmp(rank a, rank b) {
if (a.cj != b.cj)
return a.cj > b.cj;
return a.id < b.id;
}
int main() {
int n, k;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> st[i].id >> st[i].cj;
}
sort(st + 1, st + n + 1, cmp);
for (int i = 1; i <= n; i++) {
cout << st[i].id << ' ' << st[i].cj;
cout << endl;
}
return 0;
}