#include<iostream>
using namespace std;

/*マージソートでx,y座標共に昇順に並べる。（x最優先)*/
void merge( int* x, int* y, int left, int mid, int right )
{
    int ls = mid - left;
    int rs = right - mid;

    int L1[ls+1], R1[rs+1];
    int L2[ls+1], R2[rs+1];
    L1[ls] = 2000000000, R1[rs] = 2000000000;
    L2[ls] = 2000000000, R2[rs] = 2000000000;
    

    for( int i = 0; i < ls; i++ )
    {
        L1[i] = x[left+i];
        L2[i] = y[left+i];
    }
    for( int i = 0; i < rs; i++ )
    {
        R1[i] = x[mid+i];
        R2[i] = y[mid+i];
    }

    int i = 0, j = 0;
    for( int k = left; k < right; k++ )
    {
        if( L1[i] < R1[j] )
        {
            x[k] = L1[i];
            y[k] = L2[i];
            i++;
        }
        else if ( L1[i] > R1[j] )
        {
            x[k] = R1[j];
            y[k] = R2[j];
            j++;
        }
        else
        {
            if( L2[i] <= R2[j] )
            {
                x[k] = L1[i];
                y[k] = L2[i];
                i++;
            }
            else
            {
                x[k] = R1[j];
                y[k] = R2[j];
                j++;
            }
        }
    }
}

void mergeSort( int* x, int* y, int left, int right )
{
    if( left + 1 < right )
    {
        int mid = ( left + right ) / 2;
        mergeSort( x, y, left, mid );
        mergeSort( x, y, mid, right );
        merge( x, y, left, mid, right );
    }
}

int main()
{
    int n;

    cin >> n;

    int x[n], y[n];

    for( int i = 0; i < n; i++ )
        cin >> x[i] >> y[i];

    mergeSort( x, y, 0, n );

    for( int i = 0; i < n; i++ )
        cout << x[i] << " " << y[i] << endl;

    return 0;
}
