program xxxx;
var n,i,j,x,y:longint;
chr:char;
b:array[1..2000] of char;
a:array[1947..2009,1..2000] of char;
f:array[1947..2009] of integer;
begin
assign(input,'nba.in');
reset(input);
assign(output,'nba.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
x:=1;
repeat
begin
read(chr);
if chr<>' ' then
begin
b[x]:=chr;
inc(x);
end
else
begin
readln(y);
if f[y]=0 then
begin
for j:=1 to x do
a[y,j]:=b[j];
f[y]:=x;
end;
break;
end;
end
until x>1000;
end;
for i:=1947 to 2009 do
if f[i]<>0 then
begin
write(i,' ');
for j:=1 to f[i] do
write(a[i,j]);
writeln;
end;
close(input);
close(output);
end.