type
 vector=record
  nume:string;
  pct:integer;
 end;

var v:array[1..4] of vector;



 function valid (s:string; k:integer):boolean;
 var i:byte;
 begin

  valid:=true;

  for i:=1 to k do
      if s=v[i].nume then valid:=false;
 end;



 procedure score (s:string; k,p:integer);
 var i:integer;
 begin

  i:=1;

  while (v[i].nume<>s) and (i<=k) do
        inc(i);

  v[i].pct:=v[i].pct+p;
 end;



 procedure citire;
 var z,e,i,k,j,x,y:integer; c:string[1]; a,s1,s2,c1,c2:string;
 begin

  k:=0;

  for i:=1 to 6 do
      begin

       j:=1;

       while not(eoln) do
             begin

              read(c);

              s1:=''; s2:='';

              if j=1 then begin
              while (c<>' ') do
                    begin
                     if c<>' ' then s1:=s1+c;
                     read(c);
                    end;

              if valid(s1,k) then begin inc(k); v[k].nume:=s1; end;
              end

              else if j=2 then begin
              while (c<>' ') do
                    begin
                     if c<>' ' then s2:=s2+c;
                     read(c);
                    end;

              if valid(s2,k) then begin inc(k); v[k].nume:=s2; end;
              end

              else if j>2 then begin

                   read(c1,c2);

                   val(c1,x,e); val(c2,y,e);

                   if x>y then begin
                               score(s1,k,3);
                               score(s2,k,0);
                               end
                          else if x<y then begin
                                           score(s2,k,3);
                                           score(s2,k,0);
                                           end
                                           else if x=y then begin
                                                            score(s1,k,1);
                                                            score(s2,k,1);
                                                            end;

                   end;

              j:=j+1;

             end;

       readln;

      end;

  for i:=1 to k-1 do
      for j:=i+1 to k do
          if v[i].pct>v[j].pct then begin
                                    a:=v[i].nume;
                                    v[i].nume:=v[j].nume;
                                    v[j].nume:=a;
                                    z:=v[i].pct;
                                    v[i].pct:=v[j].pct;
                                    v[j].pct:=z;
                                    end;

  for i:=1 to k do
      writeln(v[i].nume);

  writeln;
 end;


begin
 citire;
end.