import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;


auto nCoin(int m) {
	int ans;
	while(m >= 500) {
		m -= 500;
		++ans;
	}
	while(m >= 100) {
		m -= 100;
		++ans;
	}
	while(m >= 50) {
		m -= 50;
		++ans;
	}
	while(m >= 10) {
		m -= 10;
		++ans;
	}
	return ans;
}

void main(){
	int t;
	while(true) {
		auto n = readInt();
		if(n == 0) return;
		if(t > 0) {
			writeln();
		}
		++t;
		auto m = readInts();
		auto k = new int[](4);
		auto l = m[0] * 10 + m[1] * 50 + m[2] * 100 + m[3] * 500 - n;
		k[3] = l/500;
		l %= 500;
		k[2] = l/100;
		l %= 100;
		k[1] = l/50;
		l %= 50;
		k[0] = l/10;
		auto c = [10, 50, 100, 500];
		for(int i; i < 4; ++i) {
			if(m[i] > k[i]) {
				writeln(c[i], " ", m[i]-k[i]);
			}
		}
	}
}