import java.io.*;
import java.util.*;

public class DWITE2 {
	public static void main (String [] args) throws IOException {
		BufferedReader inBuff = new BufferedReader(new FileReader("DATA2.txt"));
		PrintWriter outPrint = new PrintWriter(new FileWriter("OUT2.txt"));
		
		for (int x = 0; x < 5; x++) {
				int [] score = new int [5];
				String [] name = new String [5];
			
			for (int i = 0; i < 5; i++) {
				String input = inBuff.readLine();
				int pos = input.indexOf(" ");
				score[i] = Integer.parseInt(input.substring(0, pos));
				name[i] = input.substring(pos+1);
				//System.out.println(score[i] + " " + name[i]);
			}
			
			insertSort(score, name);
			
			for (int j = 0; j < 5; j++) {
				//System.out.println(score[j]);
				outPrint.println(name[j]);
			}
		}
		
		outPrint.close();
	}
	
	public static void insertSort (int[] list, String[] list2) {
		for (int i=1; i<list.length; i++) {
			int temp = list[i];
			String temp1 = list2[i];
			int k;
			for (k=i-1; k>=0 && temp>list[k]; k--) {
				list[k+1]=list[k];
				list2[k+1]=list2[k];
			}
			list[k+1] = temp;
			list2[k+1] = temp1;
		}
	}
}
