import java.util.Comparator;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, String> mouses = new TreeMap<>(Comparator.comparingInt(
                    Integer::intValue).reversed());
        while (n-- > 0) {
            int weight = sc.nextInt();
            String color = sc.next();
            mouses.put(weight, color);
        }
        for (String color : mouses.values()) {
            System.out.println(color);
        }
    }
}