#include <iostream>

using namespace std;

int main(){
  int n,j,g,h,gh;
  int j2,g2,h2,gh2;
  int ansj,ansg,ansh,ansgh;
  int i = 0;
  while(1){
    i++;
    cin >> n;
    if(n == 0) break;
    if(i != 1) cout << '\n';
    cin >> j >> g >> h >> gh;
    int sum = 0;
    sum = j*10 + g * 50 + h * 100 + gh * 500;
    int ans = 0;
    ans = sum - n;
    gh2 = ans/500;
    ans = ans%500;
    h2 = ans/100;
    ans = ans%100;
    g2 = ans/50;
    ans = ans%50;
    j2 = ans/10;
    ans = ans%10;

    if((j - j2) > 0){
      ansj = j - j2;
      cout << 10 << ' ' << ansj << '\n';
    }

    if((g - g2) > 0){
      ansg = g - g2;
      cout << 50 << ' ' << ansg << '\n';
    }

     if((h - h2) > 0){
       ansh = h - h2;
      cout << 100 << ' ' << ansh << '\n';
    }
    
    if((gh - gh2) > 0){
      ansgh = gh - gh2;
      cout << 500 << ' ' << ansgh << '\n';
    }
   
  }
}