program bbb
implicit none

integer(16) :: n, i, j, l, dumy
character(10),allocatable,dimension(:) :: s
integer(16),allocatable,dimension(:) :: t, p, q

read*, n
allocate(s(n))
allocate(t(n))
allocate(p(n))
allocate(q(n))
t=0

do i=1,n
read*, s(i), p(i)
q(i)=i
end do

p=-p

do i=1,n
l=len_trim(s(i))
 do j=1,l
 t(i)=t(i)+((iachar(s(i)(j:j))-80))*(10**(2*(11-j)))
 end do
t(i)=t(i)+p(i)
end do

do i=1,n
 do j=i+1,n
 if(t(i)>t(j)) then
 dumy=t(i)
 t(i)=t(j)
 t(j)=dumy
 dumy=q(i)
 q(i)=q(j)
 q(j)=dumy
 end if
 end do
end do

do i=1,n
write(*,'(i0)') q(i)
end do

end program