program nba;
var
i,j,n:longint;
code:integer;
s,st:string;
sz:array[0..100]of integer;
sz2:array[0..100]of string;
begin
assign(input,'nba.in');
assign(output,'nba.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(s);
st:='';
while s[length(s)]<>' ' do
begin
st:=s[length(s)]+st;
delete(s,length(s),1);
end;
sz2[i]:=s;
val(st,sz[i],code);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if sz[i]>sz[j] then begin
sz2[0]:=sz2[i];
sz2[i]:=sz2[j];
sz2[j]:=sz2[0];
sz[0]:=sz[i];
sz[i]:=sz[j];
sz[j]:=sz[0];
end;
for i:=1 to n do
writeln(sz[i],' ',sz2[i]);
close(input);
close(output);
end.