program wz;
var
a,b:array[0..500001]of string;
ans:array[0..500001]of longint;
len,i,k0,k,ha,max:longint;
s0,s1,s2:string;
function hash(s:string):longint;
var
i,j:longint;
begin
j:=1;
for i:=1 to length(s) do
j:=(j+ord(s[i])*997)mod 9997;
while (b[j]<>'')and(b[j]<>s) do j:=j+1;
hash:=j;
end;
begin
assign(input,'vote.in');
assign(output,'vote.out');
reset(input);
rewrite(output);
while s0<>'.' do
begin
readln(s0);
len:=length(s0);
k0:=pos(':',s0);
k:=hash(copy(s0,k0+1,len));
s1:=copy(s0,1,k0-1);
s2:=copy(s0,k0+1,len);
if ans[k]=0 then
begin
a[k]:=s1;
b[k]:=s2;
inc(ans[k]);
end
else
inc(ans[k]);
if max<ans[k] then
begin
max:=ans[k];
ha:=k;
end;
end;
writeln(a[ha]);
writeln(b[ha]);
close(input);
close(output);
end.