#include<stdio.h> int main(){ int n, a[100], b[100]; scanf("%d", &n); for (int i=0; i<n; i++) scanf("%d %d",&a[i], &b[i]); for (int i = 0; i<n-1; i++){ for (int j = 0; j < n-i-1; j++){ if(a[j]>a[j+1]){ int t = a[j]; a[j] = a[j+1]; a[j+1] = t; t = b[j]; b[j] = b[j+1]; b[j+1] = t; } } } for (int i = 0; i<n-1; i++){ for (int j = 0; j < n-i-1; j++){ if(b[j]>b[j+1]){ int t = a[j]; a[j] = a[j+1]; a[j+1] = t; t = b[j]; b[j] = b[j+1]; b[j+1] = t; } } } for (int i=0; i<n; i++) printf("%d %d\n", a[i], b[i]); }