import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class baekjoon11650 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static int[][] arr;
public static void main(String args[]) throws IOException{
int N;
N = Integer.parseInt(br.readLine());
arr = new int[N][2];
for(int i=0;i<N;i++){
st = new StringTokenizer(br.readLine()," ");
arr[i][0] = Integer.parseInt(st.nextToken());
arr[i][1] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr,(a1,a2) ->{
if(a1[0]==a2[0]){
return Integer.compare(a1[1], a2[1]);
}else{
return Integer.compare(a1[0], a2[0]);
}
});
for(int i=0;i<N;i++){
System.out.println(arr[i][0]+" "+arr[i][1]);
}
}
}
arrays.sort에대해서 검색해보고 Arrays.sort() 람다식으로 푸는게 제일 깔끔해보여서 람다식으로 풀었다.