coin = [10, 50, 100, 500]
change = [1,2,3,4,1,2,3,4,5] + 
          (l = [1,2,3,4,5,2,3,4,5,6]) + 
          l.map{|v| v + 1} +
          l.map{|v| v + 2} +
          l.map{|v| v + 3}
f = false
while true
  n = gets.to_i
  break if n == 0
  puts if f
  f = true
  m = gets.split.map(&:to_i)
  (0..2).each do |i|
    break if n <= 0
    r = [n / coin[i], m[i]].min
    if i > 0 && r == n / coin[i] && n % coin[i] != 0 && coin[i+1] > 0
      if change[(coin[i+1] - (n - r * coin[i])) / 10 - 1] > change[((r+1) * coin[i] - n) / 10 - 1]
        r += 1
      end
    end
    puts "#{coin[i]} #{r}" if r > 0
    n -= r * coin[i]
  end
  if n > 0
    r = n % coin[3] == 0 ? n / coin[3] : n / coin[3] + 1
    puts "#{coin[3]} #{r}"
  end
end