### constant

CS = [10, 50, 100, 500]

### subroutines

def change(pr)
  count = 0
  3.downto(0) do |i|
    d = pr / CS[i]
    pr -= d * CS[i]
    count += d
  end
  count
end

### main

first = true
loop do
  pr = gets.to_i
  break if pr == 0

  ns = gets.split.map(&:to_i)
  ds = Array.new(4){0}

  minsum = 100
  minds = Array.new(4){25}
  
  loop do
    pay = 0
    (0..3).each{|i| pay += CS[i] * ds[i]}

    if pay >= pr
      count = ds.inject(:+)
      count += change(pay - pr)
      if minsum > count
        minsum = count
        minds = ds.clone
      end
    end

    k = 0
    while k < 4
      ds[k] += 1
      break if ds[k] <= ns[k]
      ds[k] = 0
      k += 1
    end
    break if k >= 4
  end

  puts if ! first
  first = false
  
  for i in (0..3)
    if minds[i] > 0
      puts [CS[i], minds[i]].join(' ')
    end
  end
end