//Make Purse Light
#include<bits/stdc++.h>
using namespace std;

#define INF 100000
#define rep(i,n) for(int i=0; i<n; i++)

int p;
int num(int c10, int c50, int c100, int c500){
  int ret=0, x=(c10*10+c50*50+c100*100+c500*500)-p;
  while(x!=0){
    if(x>=500){ret++; x-=500;}
    else if(x>=100){ret++; x-=100;}
    else if(x>=50){ret++; x-=50;}
    else if(x>=10){ret++; x-=10;}
  }
  return ret;
}

int main(){
  bool flag=false;
  while(true){
    cin>>p;
    if(p==0)break;
    if(flag)cout<<endl;
    int c10, c50, c100, c500;
    int mn=INF, cn10=0, cn50=0, cn100=0, cn500=0;
    cin>>c10>>c50>>c100>>c500;
    rep(i,c10+1)rep(j,c50+1)rep(k,c100+1)rep(l,c500+1){
      if(i*10+j*50+k*100+l*500>=p){
        int tmp=(c10+c50+c100+c500)-(i+j+k+l)+num(i, j, k, l);//支払後のコイン数
        if(mn>tmp){mn=tmp; cn10=i; cn50=j; cn100=k; cn500=l;}
      }
    }
    if(cn10!=0)cout<<"10 "<<cn10<<endl;
    if(cn50!=0)cout<<"50 "<<cn50<<endl;
    if(cn100!=0)cout<<"100 "<<cn100<<endl;
    if(cn500!=0)cout<<"500 "<<cn500<<endl;
    flag=true;
  }
  return 0;
}