import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
static class Infor implements Comparable<Infor>{
int num;
String name;
int age;
public Infor(int num, String name, int age) {
this.num = num;
this.name = name;
this.age = age;
}
@Override
public int compareTo(Infor o) {
if(this.age == o.age) {
return this.num - o.num;
}
return this.age - o.age;
}
}
public static void main(String args[]) {
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
ArrayList<Infor> list = new ArrayList<>();
for(int i=0; i<n; i++) {
int age = kb.nextInt();
String name = kb.next();
list.add(new Infor(i, name, age));
}
Collections.sort(list);
for(int i=0; i<list.size(); i++) {
System.out.println(list.get(i).age+ " "+ list.get(i).name);
}
}
}