#include<iostream>

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

int main(){

	int r[4];
	int sum;
	int remain;
	int d[4] = {10,50,100,500};
	int c[4];
	int p[4];
	int flag = 0;
	int m;
	int minc[4];
	while(std::cin >> m, (m)){
		if(flag == 1){
			std::cout << std::endl;
		}
		flag = 1;
		int min = 20*4+1;
		rep(i,4){
			std::cin >> c[i];
			minc[i] = 0;
		}
		for(p[0]=0; p[0]<=c[0]; p[0]++){
			for(p[1]=0; p[1]<=c[1]; p[1]++){
				for(p[2]=0; p[2]<=c[2]; p[2]++){
					for(p[3]=0; p[3]<=c[3]; p[3]++){
						sum = 0;
						rep(i,4){
							sum += d[i] * p[i];
							r[i] = 0;
						}
						if(sum < m)continue;

						sum -= m;
						rep(i,4){
							while(sum >= d[3-i]){
								sum -= d[3-i];
								r[3-i]++;
							}
						}
						remain = 0;
						rep(i,4){
							remain += c[i] - p[i] + r[i];
						}
						if(remain < min){
							min = remain;
							rep(i,4){
								minc[i] = p[i];
							}
						}
					}
				}
			}
		}
		rep(i,4){
			if(minc[i] > 0){
				std::cout << d[i] << ' ' << minc[i] << std::endl;
			}
		}
	}
	return 0;
}