package boj;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class boj_11651 {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
int count = Integer.parseInt(r.readLine());
List<List<Integer>> points = new ArrayList<>();
for(int i=0 ; i<count ; i++){
List<Integer> point = Arrays.stream(r.readLine().split(" "))
.map(Integer::parseInt)
.collect(Collectors.toList());
points.add(point);
}
List<List<Integer>> sortedPoints = points.stream()
.sorted(Comparator.comparingInt((List<Integer> e) -> e.get(1))
.thenComparingInt((List<Integer> e) -> e.get(0)))
.collect(Collectors.toList());
for(List<Integer> point : sortedPoints){
w.write(point.get(0) + " " + point.get(1));
w.newLine();
}
w.flush();
}
}