#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
struct student {
char id[64];
int point;
};
void list_students(struct student* students, int cnt) {
for (int i = 0; i < cnt; i++) {
scanf("%s %d", students[i].id, &students[i].point);
}
}
void swap(struct student* a, struct student* b) {
struct student temp = *a;
*a = *b;
*b = temp;
}
void bubbleSort(struct student* students, int cnt) {
int i, j;
for (i = 0; i < cnt - 1; i++) {
for (j = 0; j < cnt - i - 1; j++) {
if (students[j].point > students[j + 1].point) {
swap(&students[j], &students[j + 1]);
}
}
}
}
int main() {
int i, cnt;
struct student stus[100];
scanf("%d", &cnt);
list_students(stus, cnt);
bubbleSort(stus, cnt);
for (i = 0; i < cnt; i++) {
printf("%s %d\n", stus[i].id, stus[i].point);
}
}