fun main(args:Array<String>?): Unit {
    val (n, t, h, l) = readLine()!!.trim().split(' ').map(String::toInt)
    val vendor = Vendor(t, h, l)
    val members = List(n){
        val (ten, hundred) = readLine()!!.trim().split(' ').map(String::toInt)
        Member(it, ten, hundred)
    }
    tailrec fun sub(vendor: Vendor, index: Int): Int {
        if (members[index].hasNoCoin()) return index
        val coins =  vendor.insert(members[index].putCoin())
        return when (coins) {
            null -> index
            else -> {
                coins.forEach { (i, c) -> members[index].receiveCoin(i, c) }
                sub(vendor, (index + 1) % n)
            }
        }
    }
    println(sub(vendor, 0) + 1)

}
enum class Coin(val value: Int){
    Ten(10), Hundred(100)
}
class Vendor(private var ten: Int, private var hundred: Int, private val tenLimit: Int) {
    private var account: Int = 0
    fun insert(coin: Coin): Collection<Pair<Int, Coin>>? {
        account += coin.value
        when(coin){
            Coin.Ten -> ++ten
            Coin.Hundred -> ++hundred
        }
        return when{
            ten > tenLimit -> null
            account >= 90 -> {
                val coins = pay(account - 90)
                account = 0
                coins
            }
            else -> listOf()
        }
    }
    private fun pay(value: Int): Collection<Pair<Int, Coin>>? {
        return if (ten * 10 >= value) {
            ten -= value / 10
            listOf(Pair(value / 10, Coin.Ten))
        }else if (ten * 10 + hundred * 100 >= value && ten * 10 >= value % 100) {
            val h = (value - ten * 10 + 99) / 100
            hundred -= h
            ten -= (value - 100 * h) / 10
            listOf(Pair(h, Coin.Hundred), Pair((value - 100 * h) / 10, Coin.Ten))
        }else {
            null
        }
    }
}
class Member(val id: Int, private var ten: Int, private var hundred: Int) {
    fun putCoin(): Coin {
        return if (ten > 0) {
            --ten
            Coin.Ten
        }else {
            --hundred
            Coin.Hundred
        }
    }
    fun hasNoCoin(): Boolean = ten == 0 && hundred == 0
    fun receiveCoin(count: Int, coin: Coin): Unit {
        when(coin){
            Coin.Ten -> ten += count
            Coin.Hundred -> hundred += count
        }
    }
}
