n = gets.to_i
a = Array.new(n)
n.times do |i|
    a[i] = gets.split << i
    a[i][1] = a[i][1].to_i
end
a.sort_by!{|i,j,k|i}
b = Hash.new{|h,k|h[k] = []}
a.each do |arr|
    b[arr[0]] << arr[1,2]
end
b.values.each do |arr|
    arr.sort_by!{|i,j|-i}
    arr.each do |i|
        puts i[1]+1
    end
end