program Files;
 
var
   f,g: Text;
   count,count2,temp,temp2,e:integer;
   s,t:string;

begin
   Assign(g,'DATA2.txt');
   Assign(f,'OUT2.txt');
   Rewrite(f);
   Reset(g);

for count2:= 1 to 5 do
begin
readln(g,s);
Val(s[length(s)], temp,e);
for count:=1 to 5 do
    begin
    readln(g,s);
    Val(s[length(s)], temp2,e);
    Delete(s, (length(s)-1), 2);
    if temp2>temp then writeln(f,s);
    end;
end;

   close(f);
end. 

