import java.io.*;
// The "Problem2" class.
public class Problem2
{
    public static void main (String[] args) throws IOException
    {
	BufferedReader in = new BufferedReader (new FileReader ("DATA2.txt"));
	PrintWriter out = new PrintWriter (new FileWriter ("OUT2.txt"));
	for (int k = 0 ; k < 5 ; k++)
	{
	    int score[] = new int [5];
	    String name[] = new String [5];
	    for (int i = 0 ; i < 5 ; i++)
	    {
		String temp = in.readLine ();
		String data[] = temp.split (" ", 2);
		score [i] = Integer.parseInt (data [0]);
		name [i] = data [1];
	    }
	    for (int i = 0 ; i < 5 ; i++)
	    {
		for (int j = i + 1 ; j < 5 ; j++)
		{
		    if (score [i] < score [j])
		    {
			int temp1 = score [i];
			score [i] = score [j];
			score [j] = temp1;
			String temp2 = name [i];
			name [i] = name [j];
			name [j] = temp2;
		    }
		}
	    }
	    for (int i = 0 ; i < 5 ; i++)
	    {
		out.println (name [i]);
	    }
	}
	out.close ();
	// Place your code here
    } // main method
} // Problem2 class

