#include<iostream>
#include<cstring>
#include<math.h>
using namespace std;
int Teams[5], goals[5];
char teams[6][101], e1[101], e2[101], g1, g2;
int getTeam(char t[101])
{
	if (strcmp(t, teams[1]) == 0)
		return 1;
	if (strcmp(t, teams[2]) == 0)
		return 2;
	if (strcmp(t, teams[3]) == 0)
		return 3;
	if (strcmp(t, teams[4]) == 0)
		return 4;
}
int main()
{
	int i, t1, t2;
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	cin >> e1 >> e2 >> g1 >> g2;
	strcpy(teams[1], e1);
	strcpy(teams[2], e2);
	goals[1] += g1; goals[2] += g2;
	if (g1 == g2)
	{
		Teams[1]++; Teams[2]++;
	}
	else
	if (g1 > g2)
		Teams[1] += 3;
	else
		Teams[2] += 3;

	cin >> e1 >> e2 >> g1 >> g2;
	strcpy(teams[3], e1);
	strcpy(teams[4], e2);
	goals[3] += g1; goals[4] += g2;
	if (g1 == g2)
	{
		Teams[3]++; Teams[4]++;
	}
	else
	if (g1 > g2)
		Teams[3] += 3;
	else
		Teams[4] += 3;

	for (i = 1; i <= 4; i++)
	{
		cin >> e1 >> e2 >> g1 >> g2;
		t1 = getTeam(e1);
		t2 = getTeam(e2);
		if (t1 == 1)
			goals[1] += g1;
		if (t1 == 2)
			goals[2] += g1;
		if (t1 == 3)
			goals[3] += g1;
		if (t1 == 4)
			goals[4] += g1;

		if (t2 == 1)
			goals[1] += g2;
		if (t2 == 2)
			goals[2] += g2;
		if (t2 == 3)
			goals[3] += g2;
		if (t2 == 4)
			goals[4] += g2;

		int v1, v2, e;
		v1 = v2 = e = 0;
		if (g1 == g2) e = 1;
		if (g1 > g2) v1 = 1;
		if (g1 < g2) v2 = 1;

		if (e == 1)
		{
			if (t1 == 1 && t2 == 2 || t2 == 1 && t1 == 2)
			{
				Teams[1]++; Teams[2]++;
			}
			if (t1 == 1 && t2 == 3 || t1 == 3 && t2 == 1)
			{
				Teams[1]++; Teams[3]++;
			}
			if (t1 == 1 && t2 == 4 || t1 == 4 && t2 == 1)
			{
				Teams[1]++; Teams[4]++;
			}
			if (t1 == 2 && t2 == 3 || t1 == 3 && t2 == 2)
			{
				Teams[3]++; Teams[2]++;
			}
			if (t1 == 2 && t2 == 4 || t1 == 4 && t2 == 2)
			{
				Teams[4]++; Teams[2]++;
			}
			if (t1 == 3 && t2 == 4 || t1 == 4 && t2 == 3)
			{
				Teams[3]++; Teams[4]++;
			}
		}

		if (v1 == 1)
		{
			if (t1 == 1)
				Teams[1] += 3;
			if (t1 == 2)
				Teams[2] += 3;
			if (t1 == 3)
				Teams[3] += 3;
			if (t1 == 4)
				Teams[4] += 3;
		}

		if (v2 == 1)
		{
			if (t2 == 1)
				Teams[1] += 3;
			if (t2 == 2)
				Teams[2] += 3;
			if (t2 == 3)
				Teams[3] += 3;
			if (t2 == 4)
				Teams[4] += 3;
		}
	}

	int  j, auxx;
	char aux[101];
	for (i = 1; i < 4; i++)
	for (j = i + 1; j <= 4; j++)
	if (Teams[i] < Teams[j])
	{
		strcpy(aux, teams[i]);
		strcpy(teams[i], teams[j]);
		strcpy(teams[j], aux);
		auxx = goals[i];
		goals[i] = goals[j];
		goals[j] = auxx;
		auxx = Teams[i];
		Teams[i] = Teams[j];
		Teams[j] = auxx;
	}
	else
	if (Teams[i] == Teams[j] && goals[i] < goals[j])
	{
		strcpy(aux, teams[i]);
		strcpy(teams[i], teams[j]);
		strcpy(teams[j], aux);
		auxx = goals[i];
		goals[i] = goals[j];
		goals[j] = auxx;
		auxx = Teams[i];
		Teams[i] = Teams[j];
		Teams[j] = auxx;
	}
	else
	if (Teams[i] == Teams[j] && goals[i] == goals[j] && strcmp(teams[i], teams[j]) > 0)
	{
		strcpy(aux, teams[i]);
		strcpy(teams[i], teams[j]);
		strcpy(teams[j], aux);
		auxx = goals[i];
		goals[i] = goals[j];
		goals[j] = auxx;
		auxx = Teams[i];
		Teams[i] = Teams[j];
		Teams[j] = auxx;
	}
	cout << teams[1] << "\n" << teams[2] << "\n" << teams[3] << "\n" << teams[4] << "\n";
}