#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct student {
int id;
int score;
} Student;
// int cmp(const void* x, const void* y) {
// if (((Student*)x)->score == ((Student*)y)->score) {
// return ((Student*)x)->id > ((Student*)y)->id;
// } else {
// return ((Student*)x)->score > ((Student*)y)->score;
// }
// }
int cmp( Student* x, Student* y) {
if (x->score == y->score) {
return x->id > y->id;
} else {
return x->score > y->score;
}
}
int main() {
Student stu[105];
int n;
while (scanf("%d", &n) != EOF) {
int a[105] = {0};
for (int i = 0; i < n; i++) {
scanf("%d %d", &stu[i].id, &stu[i].score);
}
qsort(stu, n, sizeof(Student), cmp);
for (int i = 0; i < n; i++) {
printf("%d %d\n", stu[i].id, stu[i].score);
}
}
return 0;
}