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);}
template lazyCartesianProduct(R){
	auto lazyCartesianProduct(R[][] rs ...){ return lazycartesianproduct!(R)(rs);}
	struct lazycartesianproduct(R){
		private R[][] rs; 
		private int[] ls;
		int iter=0 ,last=1;
		this (R[][] rs){
			this.rs = rs;
			foreach(r;rs) { ls ~= cast(int)(r.length); last *= r.length;}
		}
		bool empty() const { return iter == last; }
		void popFront() {iter ++; }
		void popBack() { last --; }
		R[] front() {return get(iter);}
		R[] back() {return get(last);}
		R[] get(int n){
			R[] res; 
			for(int i; i < ls.length;i ++){
				res ~= rs[i][n % ls[i]];
				n = n / ls[i];
			}
			return res;
		}
	}
}
//------------------------------
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);
		int howMany = int.max; 
		auto uses = new int[4];
		foreach (I;lazyCartesianProduct(iota(have[0]+1).array,iota(have[1]+1).array,iota(have[2]+1).array,iota(have[3]+1).array)){
			alias tmpuses = I;
			auto pay = coin.dotProduct(tmpuses);	
			if (pay < total) continue;
			int tmpHowMany = have.sum + howManyCoins(pay - total) - tmpuses.sum;
			if (tmpHowMany < howMany ){
				howMany = tmpHowMany;
				uses = tmpuses;
			}
		}
		foreach(i,u;uses){if(u >0)writeln(coin[i]," ",u);}
	}
}
int howManyCoins(int pay){
	int res;
	foreach_reverse(c;coin){
		while(pay >= c){ 
			pay -= c;res ++;
		}
	} 
	return res;
}
unittest{
	assert(lazyCartesianProduct([1,2]) == [1,2]);
}
//	foreach (I;cartesianProduct(iota(have[0]+1),iota(have[1]+1),iota(have[2]+1),iota(have[3]+1))){