#include <iostream>
#include <algorithm>
using namespace std;
struct Student
{
int num;
int grade;
} students[105];
bool cmp(Student &a, Student &b)
{
if (a.grade != b.grade)
return a.grade < b.grade;
return a.num < b.num;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> students[i].num;
cin >> students[i].grade;
}
sort(students+1, students+1+n, cmp);
for (int i = 1; i <= n; ++i)
cout << students[i].num << " " << students[i].grade << endl;
return 0;
}