var
s,s1,s2:string;
z,y:array[1..100001] of string;
x:array[0..100000] of integer;
i,j,m,n,ans:longint;
begin
assign(input,'zht1.in');
assign(output,'zht1.out');
reset(input);
rewrite(output);
while not eof do
begin
readln(s);
for i:=1 to length(s) do if s[i]=':' then break;
for j:=1 to i-1 do s1:=s1+s[j];
for j:=i+1 to length(s) do s2:=s2+s[j];
for i:=1 to n+1 do
if s2=y[i] then begin x[i]:=x[i]+1; break; end;
if i=n+1 then begin n:=n+1; z[n]:=s1; y[n]:=s2; end;
s1:='';
s2:='';
end;
for i:=n downto 1 do if x[ans]<=x[i] then ans:=i;
writeln(z[ans]);
writeln(y[ans]);
close(input);
close(output);
end.