while true
  price = gets.to_i
  break if price == 0
  coin_numbers = gets.split.map(&:to_i)
  coin_values = [10, 50, 100, 500]
  coins_and_values = coin_numbers.zip(coin_values)
  temp_price = 0
  temp_coins = [0, 0, 0, 0]
  coins_and_values.each.with_index do |zip, i|
    temp_price += zip[0] * zip [1]
    temp_coins[i] = zip[0]
    break if temp_price >= price
  end
  change = temp_price - price
  change_coins = []
  coin_values.reverse.each do |value|
    coin = change / value
    change = change % value
    change_coins.insert(0, coin)
  end
  temp_pairs = temp_coins.zip(change_coins)
  actual_coins = temp_pairs.map {|pair| pair[0] > pair[1] ? pair[0] - pair[1] : 0}
  coin_values.zip(actual_coins).each do |zip|
    puts "#{zip[0]} #{zip[1]}" if zip[1] > 0
  end
end