#include <cstdio>
#include <tuple>
#include <array>

#define coin_count 4
using namespace std;

array<int, coin_count> calc(int total, array<int, coin_count> ct, array<int, coin_count> cn) {
	int money = 0;
	for (int i = 0; i < ct.size(); i++) {
		money += ct[i] * cn[i];
	}
	int money_to_return = money - total;
	array<int, coin_count> coin_return;
	coin_return.fill(0);
	for (int i = ct.size()-1; i >= 0; --i) {
		while (money_to_return >= ct[i]) {
			money_to_return -= ct[i];
			coin_return[i]++;
		}
	}
	array<int, coin_count> coin_to_pay;
	coin_to_pay.fill(0);
	for (int i = 0; i < ct.size(); i++) {
		coin_to_pay[i] = cn[i] - coin_return[i];
	}
	return coin_to_pay;
}


int main() {
	int total;
	array<int, coin_count> ct{10, 50, 100, 500};
	array<int, coin_count> cn;
	bool first = true;
	while (true) { 
		scanf("%d", &total);
		if (total == 0) break;
		if (!first) printf("\n");
		first = false;
		scanf("%d %d %d %d", &cn[0], &cn[1], &cn[2], &cn[3]);
		array<int, coin_count> res = calc(total, ct, cn);
		for (int i = 0; i < coin_count; i++) {
			if (res[i] > 0) printf("%d %d\n", ct[i], res[i]);
		}
	}
}

