var
m:array[1..10000] of string;
a:array[1..10000] of double;
s:string;
t:double;
n,i,j:integer;
begin
readln(n);
for i:=1 to n do
begin
readln(m[i],a[i]);
end;
for i:=1 to n-1 do
begin
for j:=i+1 to n do
begin
if a[i]<a[j] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
s:=m[i];
m[i]:=m[j];
m[j]:=s;
end;
if a[i]=a[j] then
begin
if length(m[i])<length(m[j]) then
begin
if copy(m[i],1,length(m[i]))<copy(m[j],1,length(m[i])) then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
s:=m[i];
m[i]:=m[j];
m[j]:=s;
end
else
if copy(m[i],1,length(m[j]))<copy(m[j],1,length(m[j])) then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
s:=m[i];
m[i]:=m[j];
m[j]:=s;
end;
end;
end;
end;
end;
for i:=1 to n do
begin
writeln(m[i]);
end;
end.
i,j,n:integer;
s:string;
begin
readln(n);
for i:=1 to n do
begin
readln(a[i]);
readln(b[i]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if b[i]<b[j] then
begin
s:=b[i];
b[i]:=b[j];
b[j]:=s;
s:=a[i];
a[i]:=a[j];
a[j]:=s;
end
else
if b[i]=b[j] then
if a[i]<a[j] then
begin
s:=b[i];
b[i]:=b[j];
b[j]:=s;
s:=a[i];
a[i]:=a[j];
a[j]:=s;
end;
for i:=1 to n do
writeln(a[i]);
end.
i,j,n:integer;
s:string;
begin
readln(n);
for i:=1 to n do
begin
readln(a[i]);
readln(b[i]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if b[i]<b[j] then
begin
s:=b[i];
b[i]:=b[j];
b[j]:=s;
s:=a[i];
a[i]:=a[j];
a[j]:=s;
end
else
if b[i]=b[j] then
if a[i]<a[j] then
begin
s:=b[i];
b[i]:=b[j];
b[j]:=s;
s:=a[i];
a[i]:=a[j];
a[j]:=s;
end;
for i:=1 to n do
writeln(a[i]);
end.