#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct{
	char v[105];
	int points, gf, ga;
} team;

int compar(const void* a, const void* b);

int main()
{
	team echipe[4];
	char a[105], b[105], *p, c[300];
  int i, goal1, goal2;

  gets(c);
  p = strtok(c, " ");
  strcpy(a, p);
  p = strtok(NULL, " ");
  strcpy(b, p);
  p = strtok(NULL, " ");
  goal1 = *p - '0';
  p = strtok(NULL, " ");
  goal2 = *p - '0';
  strcpy(echipe[0].v, a);
  strcpy(echipe[1].v, b);
  echipe[0].gf = goal1;
  echipe[1].gf = goal2;
  echipe[0].ga = goal2;
  echipe[1].ga = goal1;
  if(goal1 == goal2)
	{
		echipe[0].points = 1;
		echipe[1].points = 1;
	}

	else if(goal1 < goal2)
	{
		echipe[0].points = 0;
		echipe[1].points = 3;
	}

	else
	{
		echipe[0].points = 3;
		echipe[1].points = 0;
	}

  gets(c);
  p = strtok(c, " ");
  strcpy(a, p);
  p = strtok(NULL, " ");
  strcpy(b, p);
  p = strtok(NULL, " ");
  goal1 = *p - '0';
  p = strtok(NULL, " ");
  goal2 = *p - '0';
  strcpy(echipe[2].v, a);
  strcpy(echipe[3].v, b);
  echipe[2].gf = goal1;
  echipe[3].gf = goal2;
  echipe[2].ga = goal2;
  echipe[3].ga = goal1;

  if(goal1 == goal2)
	{
		echipe[2].points = 1;
		echipe[3].points = 1;
	}

	else if(goal1 < goal2)
	{
		echipe[2].points = 0;
		echipe[3].points = 3;
	}

	else
	{
		echipe[2].points = 3;
		echipe[3].points = 0;
	}

  for(i = 2; i < 6; i++)
  {
		gets(c);
  p = strtok(c, " ");
  strcpy(a, p);
  p = strtok(NULL, " ");
  strcpy(b, p);
  p = strtok(NULL, " ");
  goal1 = *p - '0';
  p = strtok(NULL, " ");
  goal2 = *p - '0';
		if(!strcmp(echipe[0].v, a))
		{
			echipe[0].gf += goal1;
			echipe[0].ga += goal2;

			if(goal1 == goal2)
				echipe[0].points += 1;

			else if(goal1 < goal2)
				echipe[0].points += 0;

			else
				echipe[0].points += 3;
		}

		if(!strcmp(echipe[1].v, a))
		{
			echipe[1].gf += goal1;
			echipe[1].ga += goal2;

			if(goal1 == goal2)
				echipe[1].points += 1;

			else if(goal1 < goal2)
				echipe[1].points += 0;

			else
				echipe[1].points += 3;
		}

		if(!strcmp(echipe[2].v, a))
		{
			echipe[2].gf += goal1;
			echipe[2].ga += goal2;

			if(goal1 == goal2)
				echipe[2].points += 1;

			else if(goal1 < goal2)
				echipe[2].points += 0;

			else
				echipe[2].points += 3;
		}

		if(!strcmp(echipe[3].v, a))
		{
			echipe[3].gf += goal1;
			echipe[3].ga += goal2;

			if(goal1 == goal2)
				echipe[3].points += 1;

			else if(goal1 < goal2)
				echipe[3].points += 0;

			else
				echipe[3].points += 3;
		}

		if(!strcmp(echipe[0].v, b))
		{
			echipe[0].gf += goal2;
			echipe[0].ga += goal1;

			if(goal1 == goal2)
				echipe[0].points += 1;

			else if(goal1 < goal2)
				echipe[0].points += 3;

			else
				echipe[0].points += 0;
		}

		if(!strcmp(echipe[1].v, b))
		{
			echipe[1].gf += goal2;
			echipe[1].ga += goal1;

			if(goal1 == goal2)
				echipe[1].points += 1;

			else if(goal1 < goal2)
				echipe[1].points += 3;

			else
				echipe[1].points += 0;
		}

		if(!strcmp(echipe[2].v, b))
		{
			echipe[2].gf += goal2;
			echipe[2].ga += goal1;

			if(goal1 == goal2)
				echipe[2].points += 1;

			else if(goal1 < goal2)
				echipe[2].points += 3;

			else
				echipe[2].points += 0;
		}

		if(!strcmp(echipe[3].v, b))
		{
			echipe[3].gf += goal2;
			echipe[3].ga += goal1;

			if(goal1 == goal2)
				echipe[3].points += 1;

			else if(goal1 < goal2)
				echipe[3].points += 3;

			else
				echipe[3].points += 0;
		}
  }

  qsort(echipe, 4, sizeof(team), compar);

  for(i = 0; i < 4; i++)
		printf("%s\n", echipe[i].v);
  return 0;
}

int compar(const void* a, const void* b){
	team* teama = (team*)a;
	team* teamb = (team*)b;
	if(teama->points < teamb->points)
		return 1;
	else if(teama->points == teamb->points)
	{
		if(teama->gf - teama->ga < teamb->gf - teamb->ga)
			return 1;
		if(teama->gf - teama->ga > teamb->gf - teamb->ga)
			return -1;
		if(teama->gf - teama->ga == teamb->gf - teamb->ga)
		{
			if(teama->gf < teamb->gf)
				return 1;

			if(teama->gf > teamb->gf)
				return -1;

			if(teama->gf == teamb->gf)
				return strcmp(teama->v, teamb->v);
		}
	}

	return -1;
}