import java.io.*;

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"));
	int score[] = new int [5];
	String name[] = new String [5];

	// getting inputs
	for (int i = 0 ; i < 5 ; i++)
	{
	    for (int j = 0 ; j < 5 ; j++)
	    {
		String tmpStr = in.readLine ();
		String splitted[] = tmpStr.split (" ");

		score [j] = Integer.parseInt (splitted [0]);
		name [j] = tmpStr.substring (splitted [0].length () + 1, tmpStr.length ());
	    }


	    // processing data from here on
	    for (int x = 0 ; x < score.length ; x++)
	    {
		for (int y = 0 ; y < score.length - 1 ; y++)
		{
		    if (score [y] < score [y + 1])
		    {
			int temp = 0;
			String temp2;
			temp = score [y + 1];
			score [y + 1] = score [y];
			score [y] = temp;

			temp2 = name [y + 1];
			name [y + 1] = name [y];
			name [y] = temp2;
		    }
		}
	    }

	    for (int q = 0 ; q < 5 ; q++)
	    {
		out.println (name [q]);
	    }

	} //end of the biggest for-loop
	in.close ();
	out.close ();

    } // end of main
} // end of class


