// AOJ 2007: Make Purse Light
// 2017.10.15

#include <stdio.h>
#include <string.h>

typedef struct { int n; char f[4]; } T;
T k[2001];

int n[4];
int c[4] = { 10, 50, 100, 500 };

int pay(int p, int f[4])
{
	int i, k, cnt;

	for (cnt = 0, i = 0; i < 4; i++) {
		f[i] = 0;
		if (c[i] <= p) {
			k = p/c[i]; if (k > n[i]) k = n[i];
			f[i] = k, cnt += n[i]-k;
			p -= c[i]*k;
		}
	}
	if (p > 0) return -1;
	return cnt;
}

int main()
{
	int t, p, q, i, j, cnt, ans;
	int f[4], ff[4];

	for (p = 10; p <= 2000; p+=10) {
		for (cnt = 0, q = p, j = 3; j >= 0; j--) if (c[j] <= q) {
			cnt += q/c[j];
			q %= c[j];
			k[p].f[j] = 1;
		}
		k[p].n = cnt;
	}

	t = 0; while (scanf("%d", &p) && p > 0) {
		for (j = 0; j < 4; j++) scanf("%d", n+j);
		ans = 0x7fffffff;
		for (i = p; i <= p+5000; i+=10) {
			int x;
			if ((x = pay(i, f)) < 0) continue;
			for (j = 0; j < 4; j++) if (f[j] > 0 && k[i-p].f[j]) break;
			if (j < 4) continue;
			if ((cnt = x + k[i-p].n) < ans) {
				ans = cnt, memcpy(ff, f, sizeof(f));
			}
		}
		if (t > 0) putchar('\n'); else t = 1;
		for (j = 0; j < 4; j++) if (ff[j] > 0)
			printf("%d %d\n", c[j], ff[j]);
	}
	return 0;
}