program nba(input,output);
var
n,i,y:integer;
str:string;
ch:char;
s:array[1946..2010]of string;
begin
assign(input,'nba.in');
reset(input);
assign(output,'nba.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
str:='';
read(ch);
while not(ch in ['0'..'9']) do
begin
str:=str+ch;
read(ch);
end;
readln(y);
if y>900 then
y:=y+1000
else
y:=y+2000;
s[y]:=copy(str,1,length(str)-1);
end;
for i:=1946 to 2010 do
if s[i]<>'' then
writeln(i,' ',s[i]);
close(input);
close(output);
end.