#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

bool solve(int *ans,int tmp,int n,int &total){
  static int coin[6]={500,100,50,10,5,1};

  for(int i=0;i<6;i++){
    tmp+=n/coin[i];
    n%=coin[i];
  }

  if (tmp < total){
    total=tmp;
    return true;
  }
  return false;
}


int main(){
  int a,b,c,d;
  int n;
  int val[4]={10,50,100,500};
  int tc=0;
  while(cin>>n && n){
    if (tc)cout << endl;
    tc++;
    cin>>a>>b>>c>>d;
    int ans[4];
    int total = 1000000;

    rep(i,a+1){
      rep(j,b+1){
	rep(k,c+1){
	  rep(l,d+1){
	    int pay=i*val[0]+j*val[1]+k*val[2]+l*val[3];
	    if (pay >= n){
	      if (solve(ans,a-i+b-j+c-k+d-l,pay-n,total)){
		ans[0]=i;
		ans[1]=j;
		ans[2]=k;
		ans[3]=l;
	      }
	    }
	  }
	}
      }
    }

    rep(i,4){
      if (ans[i] != 0)
	cout <<val[i]<<" "<<ans[i]<<endl;
    }
  }
  return false;
}