n, t, h, l = gets.chomp.split.map(&:to_i)
arr = []
n.times{arr << gets.chomp.split.map(&:to_i)}
turn, bank, flag = 0, 0, false
while true
    if arr[turn] == [0, 0]
        flag = true
    else
        if arr[turn][0] > 0
            arr[turn][0] -= 1
            bank += 10
            t += 1
            flag = true if t > l
        else
            arr[turn][1] -= 1
            bank += 100
        end
        if bank >= 90
            rest = (bank - 90) / 10
            if rest > t
                flag = true
            else
                t -= rest
                arr[turn][0] += rest
                bank = 0
            end
        end
    end
    break if flag
    turn = (turn + 1) % n
end
puts turn + 1
