import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            List<Student> list = new ArrayList<>();
            while(a -- > 0){
                int id = in.nextInt();
                int score = in.nextInt();
                list.add(new Student(id,score));
            }
            Collections.sort(list);

            for(Student student : list){
                System.out.println(student.id +" "+student.score);
            }
        }
    }

    public static class Student implements Comparable<Student>{
        int id;
        int score;
        @Override
        public int compareTo(Student s1){
            if(this.score != s1.score){
                return this.score - s1.score;
            }else{
                return this.id - s1.id;
            }
        }

        public Student(int id,int score){
            this.id = id;
            this.score = score;
        }
    }
}