program guidebook
  implicit none
  integer :: n, p(100,2) = 0, i
  character(10) :: s(100)
  read(*,*) n
  do i = 1, n
    read(*,*) s(i), p(i,1)
    p(i,2) = i
  end do
  call merge_sort(s(1:n),p(1:n,:))
  do i = 1, n
    write(*,'(i0)') p(i,2)
  end do
contains
  subroutine merge_sort(s,a)
    character(10), intent(inout) :: s(:)
    integer, intent(inout) :: a(:,:)
    integer :: n, m, l, i, u
    n = size(a,1)
    m = n
    l = 1
    do while (m > 1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(s(2*(i-1)*l+1:(2*i-1)*l),a(2*(i-1)*l+1:(2*i-1)*l,:),s((2*i-1)*l+1:u),a((2*i-1)*l+1:u,:))
      end do
      l = 2*l
      m = (m+1)/2
    end do
  end
  subroutine merger(s1,a1,s2,a2)
    character(10), intent(inout) :: s1(:), s2(:)
    integer, intent(inout) :: a1(:,:), a2(:,:)
    character(10) :: s(size(s1)+size(s2))
    integer :: a(size(a1,1)+size(a2,1),size(a1,2))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(s1)
    n2 = size(s2)
    do while (i1 <= n1 .and. i2 <= n2)
      if (s1(i1) < s2(i2) .or. (s1(i1) == s2(i2) .and. a1(i1,1) >= a2(i2,1))) then
        s(i1+i2-1) = s1(i1)
        a(i1+i2-1,:) = a1(i1,:)
        i1 = i1+1
      else
        s(i1+i2-1) = s2(i2)
        a(i1+i2-1,:) = a2(i2,:)
        i2 = i2+1
       end if
    end do
    if (i1 <= n1) then
      s(i1+i2-1:n1+n2) = s1(i1:n1)
      a(i1+i2-1:n1+n2,:) = a1(i1:n1,:)
    else
      s(i1+i2-1:n1+n2) = s2(i2:n2)
      a(i1+i2-1:n1+n2,:) = a2(i2:n2,:)
    end if
    s1 = s(1:n1)
    a1 = a(1:n1,:)
    s2 = s(n1+1:n1+n2)
    a2 = a(n1+1:n1+n2,:)
  end
end program guidebook