yen = [10, 50, 100, 500]
cnt = 0
while true
  total = gets.to_i
  break if total == 0
  puts if cnt != 0
  coins = gets.split.map(&:to_i)
  back = [0] * 4
  target = 0
  for i in (0..3)
    target += yen[i] * coins[i]
  end
  target -= total
  3.downto(0) do |i|
    back[i] = target / yen[i]
    target %= yen[i]
  end
  for i in (0..3)
    puts "#{yen[i]} #{coins[i] - back[i]}" if coins[i] - back[i] > 0
  end
  cnt += 1
end