// Arup Guha
// 1/27/2024
// Solution to Kattis Problem Cups
// https://open.kattis.com/problems/cups

import java.util.*;

public class cups {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		
		// Set up array.
		cup[] list = new cup[n];
		
		for (int i=0; i<n; i++) {
			
			// Read both as strings.
			String first = stdin.next();
			String second = stdin.next();
			
			// first is diameter
			if (isPosInt(first))
				list[i] = new cup(Integer.parseInt(first), second);
			
			// second is radius
			else
				list[i] = new cup(2*Integer.parseInt(second), first);
		}
		
		// Print the cups in order.
		Arrays.sort(list);
		for (cup c: list)
			System.out.println(c);
	
	}
	
	// Returns true iff s is a positive integer (no bounds check)
	public static boolean isPosInt(String s) {
	
		// First digit.
		if (s.charAt(0) < '1' || s.charAt(0) > '9') return false;
		
		// Rest.
		for (int i=1; i<s.length(); i++)
			if (s.charAt(i) < '0' || s.charAt(i) > '9')
				return false;
				
		// Good if we get there.
		return true;
	}

}

// To custom sort, we must create a class that implements the Comparable interface.
class cup implements Comparable<cup> {

	public int diameter;
	public String color;
	
	public cup(int d, String col) {
		diameter = d;
		color = col;
	}
	
	// We must have a method compareTo that returns an int and takes in one object of our class.
	// We must return a negative int if this < other, 0 if this == other, and a pos int if this > other.
	public int compareTo(cup other) {
		
		// Smaller diameter goes first.
		if (this.diameter != other.diameter)
			return this.diameter - other.diameter;
			
		// Ties by alpha order (not needed for Kattuis, but I did this to show how
		// to custom sort with multiple tie breakers.
		return this.color.compareTo(other.color);
	}

	public String toString() {
		return color;
	}
}