import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[][] arr = new int[N][2];
StringTokenizer st;
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, (e1, e2) -> {
if(e1[1] == e2[1]) {
return e1[0] - e2[0];
} else {
return e1[1] - e2[1];
}
});
StringBuilder sb = new StringBuilder();
for(int i = 0 ; i< N ; i++) {
sb.append(arr[i][0] + " " + arr[i][1]).append('\n');
}
System.out.println(sb);
}
}
11650번을 풀었다면 인덱스만 바꿔줘서 쉽게 성공을 할 수 있다.