def change(n, t)
    count = [0,0,0,0]
    c = t - n
    [500,100,50,10].each_with_index do |a,i|
        count[3-i] += c / a
        c %= a
    end
    return count
end
loop do
    n = gets.to_i
    break if n == 0
    c = gets.split.map{|cc| cc.to_i}
    m = n
    min = [n,n,n,n]
    t = 10 * c[0] + 50 * c[1] + 100 * c[2] + 500 * c[3]
    ch = change(n, t)
    ans = [10,50,100,500].zip(c.zip(ch).map{|a,b| a > b ? a - b : 0}).select{|i,c| c > 0}
    ans.each do |a|
        puts "#{a[0]} #{a[1]}"
    end
    puts
end