program kadai
implicit none

integer  ::  n,i,j,ans
character(len=10),allocatable  ::  s(:)
!character(len=10)  ::  a
integer,allocatable  ::  p(:)

read(*,*) n

allocate(s(n))
allocate(p(n))

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

do i=1,n
    ans=min_ch(s)
    do j=1,n
        if (s(ans)==s(j) .and. p(ans)<p(j)) then
            ans=j
        end if
    end do
    write(*,*) ans
    s(ans)="zzzzzzzzzz"
    p(ans)=-1
end do

contains

function min_ch(s) result(ret)
    implicit none
    character(len=10)  ::  s(:)
    integer  ::  ret,n,i
    n=size(s)
    ret=1
    do i=2,n
        if (s(ret)>s(i)) then
            ret=i
        end if
    end do

    return
end function min_ch


end program kadai