using System;


public class Coin
{
    public int jyuen;
    public int gojyuen;
    public int hyakuen;
    public int gohyakuen;

    public Coin(int i,int j,int k,int l)
    {
        this.jyuen = i;
        this.gojyuen = j;
        this.hyakuen = k;
        this.gohyakuen = l;
    }

    public static Coin IntToCoin(int i)
    {
        Coin coin = new Coin(0, 0, 0, 0);
        if (i >= 500)
        {
            coin.gohyakuen = i / 500;
            i = i - (500 * (i / 500));
        }
        if (i >= 100)
        {
            coin.hyakuen = i / 100;
            i = i - (100 * (i / 100));
        }
        if (i >= 50)
        {
            coin.gojyuen = i / 50;
            i = i - (50 * (i / 50));
        }
        coin.jyuen = i / 10;

        return coin;

    }
    public static int SumCoin(Coin coin)
    {
        int sum = 0;
        sum = coin.jyuen + coin.gojyuen + coin.hyakuen + coin.gohyakuen;
        return sum;
    }
}


public class Make_Purse_Light
{
    static void Main(string[] args)
    {
        bool isStarted = false;

        while (true)
        {

            int n = int.Parse(Console.ReadLine());
            if (n == 0)
            {
                break;
            }
            if (isStarted) Console.WriteLine("");
            int[] coin = new int[4];
            string[] str = Console.ReadLine().Split(' ');

            for(int i = 0; i < 4; i++)
            {
                coin[i] = int.Parse(str[i]);              
            }

            int bestsum = 20 * 4;
            Coin answer = new Coin(0, 0, 0, 0);
            Coin finalanswer = new Coin(0, 0, 0, 0);
            for (int i = 0; i <= coin[0]; i++)
            {
                for (int j = 0; j <= coin[1]; j++)
                {
                    for (int k = 0; k <= coin[2]; k++)
                    {
                        for (int l = 0; l <= coin[3]; l++)
                        {
                            int sum = 10 * i + 50 * j + 100 * k + 500 * l;
                            if (sum < n) continue;
                            int change = sum - n;

                            answer = Coin.IntToCoin(change);

                            if (i != 0 & answer.jyuen != 0) continue;
                            if (j != 0 & answer.gojyuen != 0) continue;
                            if (k != 0 & answer.hyakuen != 0) continue;
                            if (l != 0 & answer.gohyakuen != 0) continue;


                            answer.jyuen = coin[0] - i + answer.jyuen;
                            answer.gojyuen = coin[1] - j + answer.gojyuen;
                            answer.hyakuen = coin[2] - k + answer.hyakuen;
                            answer.gohyakuen = coin[3] - l + answer.gohyakuen;

                            int total = Coin.SumCoin(answer);
                            if (total < bestsum)
                            {
                                finalanswer = new Coin(i, j, k, l);
                                bestsum = total;
                            }
                        }
                    }
                }
            }
            if (finalanswer.jyuen != 0)
            {
                Console.WriteLine("10 " + finalanswer.jyuen);
            }
            if (finalanswer.gojyuen != 0)
            {
                Console.WriteLine("50 " + finalanswer.gojyuen);
            }
            if (finalanswer.hyakuen != 0)
            {
                Console.WriteLine("100 " + finalanswer.hyakuen);
            }
            if (finalanswer.gohyakuen != 0)
            {
                Console.WriteLine("500 " + finalanswer.gohyakuen);
            }

            isStarted = true;
            
        }
    }
}

Measured memory_bytes: 9152