#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <stdexcept>
#include <utility>
using namespace std;

int main()
{
    int m;
    vector<tuple<int, int, int, int>> answer;
    while (cin >> m && m != 0)
    {
        tuple<int, int, int, int> coin; // = {0, 0, 0, 0};
        get<0>(coin) = 0;
        get<1>(coin) = 0;
        get<2>(coin) = 0;
        get<3>(coin) = 0;

        int ten, fifty, one_hundred, five_hundred, change = 0, used_coin, max = -10000;
        cin >> ten >> fifty >> one_hundred >> five_hundred;
        for (int i = 0; i < ten + 1; i++)
        {
            for (int j = 0; j < fifty + 1; j++)
            {
                for (int k = 0; k < one_hundred + 1; k++)
                {
                    for (int l = 0; l < five_hundred + 1; l++)
                    {
                        change = i * 10 + j * 50 + k * 100 + l * 500 - m;
                        if (change >= 0)
                        {
                            used_coin = i + j + k + l;
                            used_coin -= change / 500;
                            change = change % 500;
                            used_coin -= change / 100;
                            change = change % 100;
                            used_coin -= change / 50;
                            change = change % 50;
                            used_coin -= change / 10;
                            if (used_coin > max) //default max=0 -> (10,0,1,0,2) WA
                            {
                                get<0>(coin) = i;
                                get<1>(coin) = j;
                                get<2>(coin) = k;
                                get<3>(coin) = l;
                                max = used_coin;
                            }
                            change = 0;
                            used_coin = 0;
                        }
                    }
                }
            }
        }
        answer.push_back(coin);
    }
    for (int i = 0; i < answer.size(); i++)
    {
        if (get<0>(answer.at(i)) != 0)
        {
            cout << 10 << " " << get<0>(answer.at(i)) << endl;
        }
        if (get<1>(answer.at(i)) != 0)
        {
            cout << 50 << " " << get<1>(answer.at(i)) << endl;
        }
        if (get<2>(answer.at(i)) != 0)
        {
            cout << 100 << " " << get<2>(answer.at(i)) << endl;
        }
        if (get<3>(answer.at(i)) != 0)
        {
            cout << 500 << " " << get<3>(answer.at(i)) << endl;
        }
        if (i != answer.size() - 1)
        {
            cout << endl;
        }
    } /*    for (int i = 0; i < answer.size(); i++)
    {
        if (get<0>(answer.at(i)) != 0)
        {
            cout << 10 << " " << get<0>(answer.at(i));
            if (i != answer.size() - 1)
            {
                cout << endl;
            }
            else
            {
                if (get<1>(answer.at(i)) != 0 || get<2>(answer.at(i)) != 0 || get<3>(answer.at(i)) != 0)
                {
                    cout << endl;
                }
            }
        }
        if (get<1>(answer.at(i)) != 0)
        {
            cout << 50 << " " << get<1>(answer.at(i));
            if (i != answer.size() - 1)
            {
                cout << endl;
            }
            else
            {
                if (get<2>(answer.at(i)) != 0 || get<3>(answer.at(i)) != 0)
                {
                    cout << endl;
                }
            }
        }
        if (get<2>(answer.at(i)) != 0)
        {
            cout << 100 << " " << get<2>(answer.at(i));
            if (i != answer.size() - 1)
            {
                cout << endl;
            }
            else
            {
                if (get<3>(answer.at(i)) != 0)
                {
                    cout << endl;
                }
            }
        }
        if (get<3>(answer.at(i)) != 0)
        {
            cout << 500 << " " << get<3>(answer.at(i));
            if (i != answer.size() - 1)
            {
                cout << endl;
            }
        }
        if (i != answer.size() - 1)
        {
            cout << endl;
        }
    }*/
    return 0;
}



Measured memory_bytes: 3140