program nbazongguanjun;
var
a:array[1..50]of longint;
b:array[1..50]of string;
n,i:longint;
s:string;
code:integer;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
s:string;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
s:=b[i];
b[i]:=b[j];
b[j]:=s;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
assign (input,'nba.in');
reset (input);
assign (output,'nba.out');
rewrite (output);
readln (n);
for i:=1 to n do
begin
readln (s);
val(copy(s,length(s)-3,4),a[i],code);
b[i]:=copy(s,1,length(s)-5)
end;
sort(1,n);
for i:=1 to n do
writeln (a[i],' ',b[i]);
close (input);
close (output)
end.