#include <iostream>
#include <numeric>
using namespace std;

int main() {
    bool first = true;
    int n;
    int p[4] = {10, 50, 100, 500};
    int c[4];
    int a[4];

    while(true) {
        cin >> n;
        if(n == 0) break;
        if(!first) { cout << endl; }
        for(int i = 0; i < 4; ++i) { 
            cin >> c[i];
        }

        int change = inner_product(c, c + 4, p, 0) - n;


        for(int i = 3; i >= 0; --i) {
            a[i] = change / p[i];
            change %= p[i];
        }

        for(int i = 0; i < 4; ++i) {
            if(c[i] - a[i] > 0) {
                cout << p[i] << ' ' << c[i] - a[i] << endl;
            }
        }

        first = false;
    }
    return 0;
}