def f(x)
	k = 0
	k += x / 500
	x %= 500
	k += x / 100
	x %= 100
	k += x / 50
	x %= 50
	k + x / 10
end
	
ans = []
loop {
	price = gets.to_i
	break if price == 0
	a, b, c, d = gets.split.map &:to_i
	min = Float::INFINITY
	min_by = nil
	(0..a).each{|x|
	(0..b).each{|y|
	(0..c).each{|z|
	(0..d).each{|w|
		total = 10*x+50*y+100*z+500*w
		next if total < price
		net = f(total - price) - (x + y + z + w)
		if net < min
			min = net
			min_by = [x, y, z, w]
		end
	}
	}
	}
	}
	tmp = %w(10 50 100 500)
	ans << (0..3).map{|i| min_by[i] > 0 ? "#{tmp[i]} #{min_by[i]}\n" : nil}.compact.join
}

puts ans.join("\n")