#include <stdio.h>
int main() {
    int n;
    scanf("%d", &n);
    int i = 0;
    int Arr[n][2];
    while (i < n) {
        for (int j = 0; j < 2; j++) {
            scanf("%d", &Arr[i][j]);
        }
        i++;
    }
    int count = n;
    int p = n;
    while (p--) {
        for (int q = 0; q < p; q++) {
            if (Arr[q][0] > Arr[q + 1][0]) {
                int temporder = Arr[q + 1][0];
                Arr[q + 1][0] = Arr[q][0];
                Arr[q][0] = temporder;
                int numberorder = Arr[q + 1][1];
                Arr[q + 1][1] = Arr[q][1];
                Arr[q][1] = numberorder;
            }
        }
    }
    while (n--) {
        for (int k = 0; k < n; k++) {
            if (Arr[k][1] > Arr[k + 1][1]) {
                int temp = Arr[k + 1][1];
                Arr[k + 1][1] = Arr[k][1];
                Arr[k][1] = temp;
                int number = Arr[k + 1][0];
                Arr[k + 1][0] = Arr[k][0];
                Arr[k][0] = number;
            }
        }
    }
    for (int m = 0; m < count; m++) {
        for (int p = 0; p < 2; p++) {
            printf("%d ", Arr[m][p]);
        }
        printf("\n");
    }
    return 0;
}