#include <iostream>
#include <limits.h>


using namespace std;
int value;
int v[4]={500,100,50,10};
int c[4];
//k~o·ÌÅ¬Ì
int change(int k){
	int res=0;
	for(int i=0;i<4;i++)
	{
		res += k / v[i];
		k %= v[i];
	}
	return res;
}
int mincount,minsum;
int r[4];
int t[4];
//aÔÚÌRCðp¢éBpµ½ªbB
void dfs(int a,int b,int sum){
	if(a==4){
		if(sum<value)return;
		int count=change(sum-value)-b;
		if(count<mincount||(count==mincount&&minsum>sum)){
			minsum=sum;
			mincount=count;
			for(int i=0;i<4;i++)
				r[i]=t[i];
		}
	}else{
		for(int i=0;i<=c[a];i++){
			t[a]=i;
			dfs(a+1,b+i,sum+v[a]*i);
		}
	}
}
int main(){
	int s=0;
	for(;;){
		cin>>value;
		if(value==0)break;
		if((s++)>0)cout<<endl;
		for(int i=3;i>=0;i--)
			cin>>c[i];
		mincount=minsum=INT_MAX;
		dfs(0,0,0);
		for(int i=3;i>=0;i--){
			if(r[i]>0){
				cout << v[i] << " " << r[i] << endl;
			}
		}
	}
	return 0;
}