#include "iostream"
#include "map"
#include <utility>
#include<algorithm>
#include<vector>
using namespace std;
map<int, int>m;
typedef pair<int, int> PAIR;
int cmp(const PAIR& x, const PAIR& y)//针对PAIR的比较函数
{
    if (x.second == y.second)return x.first < y.first;
    return x.second < y.second;  //从小到大
}
int main()
{
    int n;
    cin >> n;
        int first; int second;
        for (int i = 0; i < n; ++i)
        {
            cin >> first >> second;
            m.insert(pair<int, int>(first, second));
        }
        vector<PAIR> vec(m.begin(), m.end());
        sort(vec.begin(), vec.end(), cmp);
        for (size_t i = 0; i != vec.size(); ++i) {  //输出
            cout << vec[i].first << " " << vec[i].second << endl;
        }
    return 0;
}