#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s ; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int value[4] = {10, 50, 100, 500};
int money, num[4];

vint save(int num) {
    vint res(4);
    num /= 10;
    res[0] = num % 5; num /= 5;
    res[1] = num % 2; num /= 2;
    res[2] = num % 5; num /= 5;
    res[3] = num;
    
    //cout << num*10 << " : " << res[0] << ", " << res[1] << ", " << res[2] << ", " << res[3] << endl;
    return res;
}

int main() {
    int first = true;
    while (cin >> money) {
        if (money == 0) break;
        if (!first) cout << endl;
        
        for (int i = 0; i < 4; ++i) cin >> num[i];
        
        int Min = 100000;
        int res[4];
        for (int i = 0; i <= num[0]; ++i) {
            for (int j = 0; j <= num[1]; ++j) {
                for (int k = 0; k <= num[2]; ++k) {
                    for (int l = 0; l <= num[3]; ++l) {
                        int pay = 10*i + 50*j + 100*k + 500*l;
                        if (pay < money) continue;
                        
                        int amari = pay - money;
                        vint oturi = save(amari);
                        
                        if (i > 0 && oturi[0] > 0) continue;
                        if (j > 0 && oturi[1] > 0) continue;
                        if (k > 0 && oturi[2] > 0) continue;
                        if (l > 0 && oturi[3] > 0) continue;
                        
                        int tmp = num[0]-i+oturi[0] + num[1]-j+oturi[1] + num[2]-k+oturi[2] + num[3]-l+oturi[3];
                        
                        //cout << "(" << i << "," << j << "," << k << "," << l << ") : " << pay << ", " << amari << ", " << oturi << " ; " << tmp << endl;
                        
                        if (chmin(Min, tmp)) {
                            res[0] = i;
                            res[1] = j;
                            res[2] = k;
                            res[3] = l;
                        }
                    }
                }
            }
        }
        for (int i = 0; i < 4; ++i) {
            if (res[i] > 0) {
                cout << value[i] << " " << res[i] << endl;
            }
        }
        first = false;
    }
    
    return 0;
}


Measured memory_bytes: 1192