#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define _GLIBCXX_DEBUG

void printv(vector<int> v) {
  for (int i : v)
    cout << i << " ";
  cout << endl;
}

vector<int> coins = {10, 50, 100, 500};

//お釣りの枚数を硬貨の種類ごとに返す。
vector<int> cntChange(int now) {
  vector<int> res(4, 0);
  rep(i, 4) {
    int cntCoin = now / coins[3 - i];
    res[3 - i] += cntCoin;
    now %= coins[3 - i];
  }
  return res;
}

int main() {
  bool first = true;
  while (true) {
    int p;
    cin >> p;
    if (!p)
      break;
    if (!first)
      cout << endl;
    else
      first = false;

    vector<int> cntC(4);
    int summ = 0;
    for (int i = 0; i < 4; i++) {
      cin >> cntC[i];
      summ += coins[i] * cntC[i];
    }
    vector<int> changes = cntChange(summ - p);
    for (int i = 0; i < 4; i++) {
      int ans = cntC[i] - changes[i];
      if (ans>0)
        cout << coins[i] << " " << ans << endl;
    }
  }
}

