count = 0
c = [10, 50, 100, 500]
while true do
  price = gets.to_i
  break if price.zero?
  puts if !count.zero?
  b = gets.split.map(&:to_i)
  total = (b.zip(c)).map{|x, y| x * y}.reduce(:+)
  change = total - price
  f = []
  c.reverse.each{|x|
    f.unshift change / x
    change %= x
  }
  4.times{|i| puts "#{c[i]} #{(b[i] - f[i])}" if b[i] - f[i] > 0 }
  count += 1
end