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 + 1}
    m = n
    min = [n,n,n,n]
    c[0].times do |i|
        c[1].times do |j|
            c[2].times do |k|
                c[3].times do |l|
                    t = 10 * i + 50 * j + 100 * k + 500 * l
                    next if t < n
                    ch = change(n, t)
                    count = ch.inject(:+) + c.inject(:+) - 4 - i - j - k - l
                    next if (i > 0 && ch[0] > 0) || (j > 0 && ch[1] > 0) || (k > 0 && ch[2] > 0) || (l > 0 && ch[3] > 0)
                    if count < m
                        m = count
                        min = [i,j,k,l]
                    end
                end
            end
        end
    end
    ans = [10,50,100,500].zip(min).select{|i,c| c > 0}
    ans.each do |a|
        puts "#{a[0]} #{a[1]}"
    end
    puts
end