N = gets.to_i

array = []
N.times do |i|
  tmp = gets.split
  array << { s: tmp[0], p: tmp[1].to_i, n: i+1 }
end

def bubble_sort(array)
  ary = array.dup
  pos_max = ary.length - 1
  (0...(pos_max)).each{ |n|
    (0...(pos_max - n)).each{ |ix|
      # 隣と比較して前が大きかったら後ろと交換
      iy = ix + 1
      ary[ix], ary[iy] = ary[iy], ary[ix] if ary[ix][:s] > ary[iy][:s]
      if (ary[ix][:s] <=> ary[iy][:s]) == 0
        ary[ix], ary[iy] = ary[iy], ary[ix] if ary[ix][:p] < ary[iy][:p]
      end
    }
  }
  ary
end
ary = bubble_sort(array)

ary.each do |i| 
 puts i[:n]
end

