#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int z[]={10,50,100,500};
  int i=0;
  while(cin>>n,n){
    if(i) cout<<endl;
    int a[4]; cin>>a[0]>>a[1]>>a[2]>>a[3];
    int x=10*a[0]+50*a[1]+100*a[2]+500*a[3]-n;
    int p[4]={};
    for(i=3;i>=0;--i){
      p[i]=x/z[i];
      x-=p[i]*z[i];
    }
    for(i=0;i<4;++i)
      if(a[i]>p[i])
        cout<<z[i]<<' '<<a[i]-p[i]<<endl;
  }
  return 0;
}