

def back_oturigation(fee, coin_values, coin_nums):

    """

    1. ????????????????????????????????£??????????????????

    2. 1????????????????????????????????????????????????????????????

       ???????????§?????????????????????-> ?°????????????????????¶???????????????????

    3. 2????????????????????°?????????????????????????????????????????????

    """

    # 1.

    oturi = coin_values[0] * coin_nums[0] \

            + coin_values[1] * coin_nums[1] \

            + coin_values[2] * coin_nums[2] \

            + coin_values[3] * coin_nums[3] \

            - fee

    use_coins = [0] * len(coin_values)

    no_use_coins = [0] * len(coin_values)



    # 2.

    for i in range(len(coin_values) - 1, -1, -1):

        no_use_coins[i] = int(oturi / coin_values[i])

        oturi = oturi - (coin_values[i] * no_use_coins[i])



    # 3.

    for i in range(0, len(use_coins), 1):

        use_coins[i] = coin_nums[i] - no_use_coins[i]

        if use_coins[i] > 0:

            print(str(coin_values[i]) + ' ' + str(use_coins[i]))



if __name__ == "__main__":

    first = True

    while (True):

        total_fee = int(input(''))

        if total_fee == 0:

            break

        if first:

            first = False

        else:

            print('')

        coins = input('')

        coins = coins.split(' ')  # 10, 50, 100, 500????????§????????????

        coins = [int(coin) for coin in coins]

        coin_values = [10, 50, 100, 500]

        back_oturigation(total_fee, coin_values, coins)

def back_oturigation(fee, coin_values, coin_nums):

    """

    1. ?????????????????????????????????£??????????????????

    2. 1????????????????????????????????????????????????????????????

       ????????????§?????????????????????-> ??°?????????????????????¶???????????????????

    3. 2?????????????????????°?????????????????????????????????????????????

    """

    # 1.

    oturi = coin_values[0] * coin_nums[0] \

            + coin_values[1] * coin_nums[1] \

            + coin_values[2] * coin_nums[2] \

            + coin_values[3] * coin_nums[3] \

            - fee

    use_coins = [0] * len(coin_values)

    no_use_coins = [0] * len(coin_values)

 

    # 2.

    for i in range(len(coin_values) - 1, -1, -1):

        no_use_coins[i] = int(oturi / coin_values[i])

        oturi = oturi - (coin_values[i] * no_use_coins[i])

 

    # 3.

    for i in range(0, len(use_coins), 1):

        use_coins[i] = coin_nums[i] - no_use_coins[i]

        if use_coins[i] > 0:

            print(str(coin_values[i]) + ' ' + str(use_coins[i]))

 

if __name__ == "__main__":

    first = True

    while (True):

        total_fee = int(input(''))

        if total_fee == 0:

            break

        if first:

            first = False

        else:

            print('')

        coins = input('')

        coins = coins.split(' ')  # 10, 50, 100, 500?????????§????????????

        coins = [int(coin) for coin in coins]

        coin_values = [10, 50, 100, 500]

        back_oturigation(total_fee, coin_values, coins)

def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ???????????§?????????????????????-> ?°????????????????????¶???????????????????
    3. 2????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = (
        coin_values[0] * coin_nums[0]
        + coin_values[1] * coin_nums[1]
        + coin_values[2] * coin_nums[2]
        + coin_values[3] * coin_nums[3]
        - fee
    )
    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)
    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])
    # 3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + " " + str(use_coins[i]))


if __name__ == "__main__":
    first = True
    while True:
        total_fee = int(input(""))
        if total_fee == 0:
            break
        if first:
            first = False
        else:
            print("")
        coins = input("")
        coins = coins.split(" ")  # 10, 50, 100, 500????????§????????????
        coins = [int(coin) for coin in coins]
        coin_values = [10, 50, 100, 500]
        back_oturigation(total_fee, coin_values, coins)

def back_oturigation(fee, coin_values, coin_nums):
    """
    1. ?????????????????????????????????£??????????????????
    2. 1????????????????????????????????????????????????????????????
       ????????????§?????????????????????-> ??°?????????????????????¶???????????????????
    3. 2?????????????????????°?????????????????????????????????????????????
    """
    # 1.
    oturi = (
        coin_values[0] * coin_nums[0]
        + coin_values[1] * coin_nums[1]
        + coin_values[2] * coin_nums[2]
        + coin_values[3] * coin_nums[3]
        - fee
    )
    use_coins = [0] * len(coin_values)
    no_use_coins = [0] * len(coin_values)
    # 2.
    for i in range(len(coin_values) - 1, -1, -1):
        no_use_coins[i] = int(oturi / coin_values[i])
        oturi = oturi - (coin_values[i] * no_use_coins[i])
    # 3.
    for i in range(0, len(use_coins), 1):
        use_coins[i] = coin_nums[i] - no_use_coins[i]
        if use_coins[i] > 0:
            print(str(coin_values[i]) + " " + str(use_coins[i]))


if __name__ == "__main__":
    first = True
    while True:
        total_fee = int(input(""))
        if total_fee == 0:
            break
        if first:
            first = False
        else:
            print("")
        coins = input("")
        coins = coins.split(" ")  # 10, 50, 100, 500?????????§????????????
        coins = [int(coin) for coin in coins]
        coin_values = [10, 50, 100, 500]
        back_oturigation(total_fee, coin_values, coins)

-    1. ????????????????????????????????£?????????????????? +    1. ?????????????????????????????????£?????????????????? -       ???????????§?????????????????????-> ?°????????????????????¶??????????????????? -    3. 2????????????????????°????????????????????????????????????????????? +       ????????????§?????????????????????-> ??°?????????????????????¶??????????????????? +    3. 2?????????????????????°????????????????????????????????????????????? -        coins = coins.split(" ")  # 10, 50, 100, 500????????§???????????? +        coins = coins.split(" ")  # 10, 50, 100, 500?????????§????????????