program nba;
var
n,i,j,julu,k,l:longint;
s,year,na:array[1..50] of string;
long:array[1..50] of longint;
t:string;
begin
assign(input,'nba.in');
reset(input);
assign(output,'nba.out');
rewrite(output);
readln(n);
for i:=1 to n do readln(s[i]);
for i:=1 to n do long[i]:=length(s[i]);
for i:=1 to n do
begin
year[i]:=copy(s[i],long[i]-3,4);
na[i]:=copy(s[i],1,long[i]-5);
end;
for i:= 1 to n-1 do
for j:=i+1 to n do
if (year[i]>year[j])and(year[j]<>'')and(i<>j)
then
begin
t:=year[i]; year[i]:=year[j]; year[j]:=t;
t:=na[i]; na[i]:= na[j]; na[j]:=t;
end
else
begin
for l:=j to n do
if (year[i]=year[l])and(year[i]<>'')and(year[l]<>'')and(i<>l)
then
begin
if l>i then for k:=l to n do
begin
year[k]:=year[k+1];
na[k]:=na[k+1];
if (year[i]>year[l])and(year[l]<>'')and(i<>l)then
begin
t:=year[i]; year[i]:=year[l]; year[l]:=t;
t:=na[i]; na[i]:= na[l]; na[l]:=t;
end;
end
else for k:=i to n do
begin
year[k]:=year[k+1];
na[k]:=na[k+1];
if (year[i]>year[l])and(year[l]<>'')and(i<>l)then
begin
t:=year[i]; year[i]:=year[l]; year[l]:=t;
t:=na[i]; na[i]:= na[l]; na[l]:=t;
end
end;
end;
end;
for i:=1 to n do
writeln(year[i],' ',na[i]);
close(input);
close(output);
end.