import java.util.*

fun main(args:Array<String>):Unit {
    var isFirst = true
    while(true){
        val account = readLine()!!.toInt()
        if (account == 0) break
        if (!isFirst) println()
        isFirst = false
        val (t, ft, h, fh) = readLine()!!.split(' ').map(String::toInt)
        val bill = Coins(t, ft, h, fh)
        val rest = Coins.payByCoin(bill.account() - account)
        bill.coins().zip(rest.intersection(bill).coins()).map{(b, r) ->
            Pair(b.first, b.second - r.second)
        }.filter{it.second != 0}.forEach {
            println("${it.first} ${it.second}")
        }
    }
}
class Coins(val ten:Int, val fifty:Int, val hundred:Int, val fiveHundred:Int){
    fun intersection(other:Coins):Coins{
        return Coins(minOf(ten, other.ten), minOf(fifty, other.fifty), minOf(hundred, other.hundred), minOf(fiveHundred, other.fiveHundred))
    }
    companion object {
        fun payByCoin(account: Int): Coins {
            return Coins((account % 50) / 10, (account % 100) / 50, (account % 500) / 100, account / 500)
        }
    }
    fun coins():Iterable<Pair<Int, Int>> {
        return listOf(Pair(10, ten), Pair(50, fifty), Pair(100, hundred), Pair(500, fiveHundred))
    }
    fun account():Int = coins().map{(a, b) -> a * b}.sum()
}
