#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef struct {
int num; //입력 순서 저장
int age;
string name;
}Person;
int cmp(const Person& a, const Person& b)
{
if (a.age == b.age) return a.num < b.num; //나이가 같다면 입력 순으로 올림차순
else return a.age < b.age; //나이순으로 올림차순
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
Person* arr = new Person[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i].age >> arr[i].name;
arr[i].num = i;
}
sort(arr, arr + n, cmp);
for (int i = 0; i < n; i++)
cout << arr[i].age << " " << arr[i].name << '\n';
delete[] arr;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgc3RydWN0IHsKCWludCBudW07CQkvL+yeheugpSDsiJzshJwg7KCA7J6lCglpbnQgYWdlOwoJc3RyaW5nIG5hbWU7Cn1QZXJzb247CgppbnQgY21wKGNvbnN0IFBlcnNvbiYgYSwgY29uc3QgUGVyc29uJiBiKQp7CglpZiAoYS5hZ2UgPT0gYi5hZ2UpIHJldHVybiBhLm51bSA8IGIubnVtOwkvL+uCmOydtOqwgCDqsJnri6TrqbQg7J6F66ClIOyInOycvOuhnCDsmKzrprzssKjsiJwKCWVsc2UgcmV0dXJuIGEuYWdlIDwgYi5hZ2U7CQkJCQkvL+uCmOydtOyInOycvOuhnCDsmKzrprzssKjsiJwKfQppbnQgbWFpbih2b2lkKQp7Cglpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CgljaW4udGllKE5VTEwpOwoKCWludCBuOwoJY2luID4+IG47CgoJUGVyc29uKiBhcnIgPSBuZXcgUGVyc29uW25dOwoKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQoJewoJCWNpbiA+PiBhcnJbaV0uYWdlID4+IGFycltpXS5uYW1lOwoJCWFycltpXS5udW0gPSBpOwoJfQoKCXNvcnQoYXJyLCBhcnIgKyBuLCBjbXApOwoKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQoJCWNvdXQgPDwgYXJyW2ldLmFnZSA8PCAiICIgPDwgYXJyW2ldLm5hbWUgPDwgJ1xuJzsKCglkZWxldGVbXSBhcnI7CglyZXR1cm4gMDsKfQ==