// Arup Guha
// 1/25/2010
// Solution to UF Sample Contest Problem: MEOWIST

import java.io.*;
import java.util.*;

public class meowist implements Comparable<meowist> {

	// Part of our object.	
	public String name;
	public int age;
	
	public meowist(String n, int a) {
		name = n;
		age = a;
	}
	
	// This is how we compare them.
	public int compareTo(meowist other) {
		if (this.age > other.age)
			return -1;
		if (this.age < other.age)
			return 1;
		return this.name.compareTo(other.name);
	}
	
	// Their output spec just prints this...
	public String toString() {
		return name;
	}
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		
		// Since we don't know how many, use this.
		ArrayList<meowist> all = new ArrayList<meowist>();
		
		// Add each item to the array list.
		while (stdin.hasNext()) {
			String name = stdin.next();
			int age = stdin.nextInt();
			all.add(new meowist(name,age));	
		}
		
		// Sort and print =)
		Collections.sort(all);
		
		for (int i=0; i<all.size(); i++) 
			System.out.println(all.get(i));
	}
}