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

int coin(int s){
if(s < 0) return 1<<28;
return s/500 + (s%500)/100 + (s%100)/50 + (s%50)/10;
}

int main(){
bool flag = false;

int n; 
while(1){
int a, b, c, d;
cin >> n;
if(n == 0) break;
if(flag) cout << endl;
else flag = true;
cin >> a >> b >> c >> d;
int ans = INT_MAX;
int x, y, z, w;
for(int i = 0; i <= a; i++){
for(int j = 0; j <= b; j++){
for(int t = 0; t <= c; t++){
for(int s = 0; s <= d; s++){
int rem = coin(-n+i*10+j*50+t*100+s*500);
rem += a-i+b-j+c-t+d-s;
if(ans > rem){
ans = rem;
x = i;
y = j;
z = t;
w = s;
}
}
}
}
}
if(x) cout << 10 << " " << x << endl;
if(y) cout << 50 << " " << y << endl;
if(z) cout << 100 << " " << z << endl;
if(w) cout << 500 << " " << w << endl;
}

}