#!/usr/bin/perl
use 5.14.2;
use warnings;

my %teams = ();
my $i = 0;
while($i < 6)
{
	my ($t1, $t2, $s1, $s2) = split ' ', <>;
	$teams{$t1} += 3 and $teams{$t2} += 0 if $s1 > $s2;
	$teams{$t2} += 3 and $teams{$t1} += 0 if $s2 > $s1;
	$teams{$t2} ++ and $teams {$t1}++ if $s1 == $s2;
	$i++;
}

foreach my $team (reverse sort { $teams{$a} <=> $teams{$b} or $b cmp $a } keys %teams) {
    say $team;
}