      module piyo
      implicit none
      
      type rest
        character(10) :: s
        integer :: p,num
      end type
      
      contains
      subroutine sortS( r )
        implicit none
        type(rest),intent(inout) :: r(:)
        type(rest) :: buffer
        integer :: i,k,len
        
        len = size(r)
        
        do i = 1,len-1
          do k = i+1,len
            if( r(i)%s(:)>r(k)%s(:) )then
              buffer = r(i)
              r(i) = r(k)
              r(k) = buffer
            end if
          end do
        end do
      end subroutine
      
      function sortP( r ) result( res )
        implicit none
        type(rest) :: r(:)
        type(rest) :: buffer
        type(rest),allocatable :: res(:)
        integer :: i,k,len
        
        len = size(r)
        
        do i = 1,len-1
          do k = i+1,len
            if( r(i)%p<r(k)%p )then
              buffer = r(i)
              r(i) = r(k)
              r(k) = buffer
            end if
          end do
        end do
        res = r
      end
      end module piyo
      
      
      PROGRAM GuideBook
      use piyo
      IMPLICIT NONE
      integer :: n
      type(rest),allocatable :: restaurant(:)
      integer :: i,len,k
      character(10) :: buffer
      
      read*,n
      allocate( restaurant(n) )
      do i = 1,n
        read*,restaurant(i)%s,restaurant(i)%p
        restaurant(i)%num = i
      end do
      
      call sortS( restaurant )
      
      
      i = 1
      do while(.true.)
        len = 0
        do k = 1,n
          if( restaurant(k)%s(1:10)==restaurant(i)%s(1:10) )then
            len = len + 1
          end if
        end do
        restaurant(i:i+len-1) = sortP( restaurant(i:i+len-1) )
        i = i+len
        
        if( i>=n )then
          exit
        end if
      end do
      
      
      
   !   print *,n
   !   do i = 1,n
   !     print*,restaurant(i)
   !   end do
      
      do i = 1,n
        print*,restaurant(i)%num
      end do
      
      END PROGRAM