import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
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);}
//------------------------------
const coin = [10,50,100,500];
void main(){	
	int total;
	read(total);
	while(total){
		auto have = new int[4];
		readArray(have);
		int howMany = int.max; 
		auto uses = new int[4];
		foreach(i0;iota(have[0]+1)){
			foreach(i1;iota(have[1]+1)){
				foreach(i2;iota(have[2]+1)){
					foreach(i3;iota(have[3]+1)){
						auto tmpuses = [i0,i1,i2,i3];
						auto pay = i0 * coin[0] + i1 * coin[1] + i2 * coin[2] + i3 * coin[3];	
						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);}
		read(total);
		if (total) writeln();
	}
}
int howManyCoins(int pay){
	int res;
	foreach_reverse(i,c;coin){
		while(pay >= c){ 
			pay -= c;res ++;
		}
	} 
	return res;
}