#include <fstream>
#include <algorithm>
#include <sstream>
using namespace std;

bool comp (string i,string j) {
	istringstream stiin,stiiin;
	int t1,t2;
	stiin.str(i);
	stiiin.str(j);
	stiin >> t1;
	stiiin >> t2;
	if (t1 == t2)
		return i>j;
	return i<j;
}

int main() {
	ifstream fin;
	ofstream fout;
	fin.open("DATA2.txt");
	fout.open("OUT2.txt");

	string scores[5],test;
	int i,j,k,temp,t2;
	for (i=1;i<=5;i++) {
		for (j=0;j<5;j++) {
			getline(fin,scores[j]);
		}
		sort(scores,scores+5,comp);
		for (j=4;j>=0;j--) {
			istringstream stin;
			stin.str(scores[j]);
			stin >> temp;
			getline(stin,test);
			fout << test.substr(1,test.length()-1) << "\n";
		}
	}

	fin.close();
	fout.close();
	return 0;
}

