def calc(s,c)
  num=Array.new(4)
  num[3]=s/500
  s=s-500*num[3]
  num[2]=s/100
  s=s-100*num[2]
  num[1]=s/50
  s=s-50*num[1]
  num[0]=s/10
  return num
end

while(money=gets.to_i)
  if money==0
    break
  end
  c=gets.chomp.split(/ /).map{|i| i.to_i}
  m=[10,50,100,500]
  sum=0
  for i in 0..3
    sum+=c[i]*m[i]
  end
  t=calc(sum-money,c)
  for i in 0..3
    if c[i]-t[i]>0
      print m[i]," ",c[i]-t[i],"\n"
    end
  end
  print "\n"
end