#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#include <cassert>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
#define vi vector<int>
using namespace std;
using ll = long long;

// ----ここから下は以前競プロをやっていた時に使っていたものです----　

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

struct s{
  int p,i,r;
};

//比較関数（降順）
bool cmpP(const s &a, const s &b){
  return a.p > b.p;
}

//比較関数（昇順）
bool cmpI(const s &a, const s &b){
  return a.i < b.i;
}

// ----本問について----
// 問題：Make Purse Light
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/2007
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
int m,c10,c50,c100,c500;

// 代金と払った額からおつりを計算する関数
vector<int> calcChange(int paid){
  vector<int> cashes(4);
  if (m > paid){ cashes[0]=-1; return cashes;}
  int change = paid - m;
  cashes[3] = change / 500;
  change %= 500;
  cashes[2] = change / 100;
  change %= 100;
  cashes[1] = change / 50;
  change %= 50;
  cashes[0] = change / 10;
  
  return cashes;
}

int solve() {
  vector<int> answer(4);
  cin >> c10 >> c50 >> c100 >> c500;
  int min = INT_MAX;
  rep(i,c10 + 1){
    rep(j, c50 + 1){
      rep(k, c100 + 1){
        rep(l, c500 + 1){
          int paid = 10*i + 50*j + 100*k + 500*l;
          if (calcChange(paid)[0]!=-1){
            vector<int> cashes(4);
            cashes = calcChange(paid);
            int walletCounts = (c10-i+cashes[0]) + (c50-j+cashes[1]) + (c100-k+cashes[2]) + (c500-l+cashes[3]);
            // cout << "paid: " << paid << " walletCounts: " << walletCounts << " {" << cashes[0] << "," << cashes[1] << "," << cashes[2] << "," << cashes[3] << "}" << endl;
            if (min > walletCounts){
              min = walletCounts;
              answer[0]=i;
              answer[1]=j;
              answer[2]=k;
              answer[3]=l;
            }
          }
        }
      }
    }
  }

  if (answer[0] != 0){ cout << "10 " << answer[0] << endl;}
  if (answer[1] != 0){ cout << "50 " << answer[1] << endl;}
  if (answer[2] != 0){ cout << "100 " << answer[2] << endl;}
  if (answer[3] != 0){ cout << "500 " << answer[3] << endl;}


  return 0;
}

int main()
{
  int first = 0;
  //cout << fixed << setprecision(10);
  while (cin >> m && m > 0){
    if (first != 0){ cout << endl; }
    solve();
    first = 1;
  }


  return 0;
}



Measured memory_bytes: 3068