import std.stdio;
import std.array;
import std.conv;
import std.string;

void main() {
	int [] c = [10, 50, 100, 500];

	bool flg = false;
	while(1) {
		int P;
		string s;
		string [] arrs;
		int [] a, b;
		int sum;

		P = to!int(chomp(readln()));
		if(P == 0) break;
		s = readln();
		arrs = split(s);
		a.length = b.length = c.length;
		for(int i = 0; i < arrs.length; i++) {
			a[i] = to!int(arrs[i]);
			sum += to!int(arrs[i]) * c[i];
		}
		int rest = sum - P;

		for(int i = to!int(c.length)-1; i >= 0; i--) {
			b[i] = rest / c[i];
			rest = rest % c[i];
		}

		if(flg) writeln("");
		flg = true;

		for(int i = 0; i < b.length; i++) {
			if(b[i] < a[i])
				writef("%d %d\n", c[i], a[i]-b[i]);
		}
	}
}