import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split(); if (line.length < args.length) return;foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
//------------------------------
//1980-430 = 1550 = 50 + 3 * 500 
//1980 = 3*500 + 3*100 + 3*50 + 3*10
//430 = 3*100 + 2*50 + 3*10
//??¨??????????????´????????£??????????¢????(????¬???????)????????????????????§
//???????????° - ?????£????????° ??? ????????°??????
const coin = [10,50,100,500];
void main(){
	int total;
	for(read(total); total ; read(total), write(total ? "\n":"")){
		auto have = new int[4];
		readArray(have);
		auto all = dotProduct(coin,have) - total;
		auto all_change = new int[4];
		foreach_reverse(i;iota(4)){
			all_change[i] = all/coin[i];
			all %= coin[i];
		}
		foreach(u;zip(have,all_change,coin))
			if(u[0]-u[1]>0) writeln(u[2]," ",u[0]-u[1]);
	}
}