type team=record
        p,g:integer;
        nm:string;
     end;
var s,n1,n2:string;
    aux:team;
    t:array[0..4] of team;
    x,i,j,s1,s2,n:byte;
begin
//assign(input,'a.in');reset(input);
//assign(output,'a.out');rewrite(output);
n:=0;
for i:=1 to 6 do begin
readln(s);
x:=pos(' ',s);
n1:=copy(s,1,x-1);
delete(s,1,x);
x:=pos(' ',s);
n2:=copy(s,1,x-1);
delete(s,1,x);
x:=pos(' ',s);
val(copy(s,1,x-1),s1);
delete(s,1,x);
val(copy(s,1,length(s)),s2);
for j:=1 to n do
if t[j].nm=n1 then break;
if t[j].nm<>n1 then begin inc(n);t[n].nm:=n1;t[n].g:=s1;
 if s1>s2 then t[n].p:=3 else
 if s1=s2 then t[n].p:=1;
end else
if t[j].nm=n1 then begin
 inc(t[j].g,s1);
 if s1>s2 then inc(t[j].p,3) else
 if s1=s2 then inc(t[j].p,1);
end;
for j:=1 to n do
if t[j].nm=n2 then break;
if t[j].nm<>n2 then begin inc(n);t[n].nm:=n2;t[n].g:=s2;
 if s1<s2 then t[n].p:=3 else
 if s1=s2 then t[n].p:=1;
end else
if t[j].nm=n2 then begin
 inc(t[j].g,s2);
 if s1<s2 then inc(t[j].p,3) else
 if s1=s2 then inc(t[j].p,1);
end;
end;
for i:=1 to 4 do
for j:=1 to 4 do
if(t[i].p>t[j].p)or((t[i].p=t[j].p)and(t[i].g>t[j].g))or
((t[i].p=t[j].p)and(t[i].g=t[j].g)and(t[i].nm<t[j].nm))then begin
aux:=t[i];t[i]:=t[j];t[j]:=aux;end;
for i:=1 to 4 do writeln(t[i].nm);
end.