#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main(){

  int N, a, b, c, d, e;
  int f, g, h, i;
  bool tmp = true;
  while(cin >> N && N > 0){
    cin >> a >> b >> c >> d;
    if(tmp){
      tmp = false;
    }else{
      cout << endl;
    }
    e = 10*a + 50*b + 100*c + 500*d - N;
    i = e/500;
    h = (e-500*i)/100;
    g = (e-500*i-100*h)/50;
    f = (e-500*i-100*h-50*g)/10;

    if(a > f) cout << 10 << " " << a-f << endl;
    if(b > g) cout << 50 << " " << b-g << endl;
    if(c > h) cout << 100 << " " << c-h << endl;
    if(d > i) cout << 500 << " " << d-i << endl;



  }

}
