#include <stdio.h>

int main(void)
{
    int payment, x, l, c, d, total, x2, l2, c2, d2;

    scanf("%d", &payment);
    while(1)
    {
        scanf("%d %d %d %d", &x, &l, &c, &d);

        total = 10 * x + 50 * l + 100 * c + 500 * d - payment;
        d2 = total / 500, total %= 500;
        c2 = total / 100, total %= 100;
        l2 = total / 50, total %= 50;
        x2 = total / 10;

        if(x > x2) printf("10 %d\n", x - x2);
        if(l > l2) printf("50 %d\n", l - l2);
        if(c > c2) printf("100 %d\n", c - c2);
        if(d > d2) printf("500 %d\n", d - d2);

        scanf("%d", &payment);

        if(!payment) break;
        else puts("");
    }

    return 0;
}