has[4];
unit[]={10,50,100,500};
cnt[4],cntmax,yenmin,ans[4];
F(yenrest,j,cntsum){
	int i;
	if(j<0){
		if(yenrest<=0){
			yenrest=-yenrest;
			cntsum-=yenrest/500+yenrest%500/100+yenrest%100/50+yenrest%50/10;
			if(cntsum>cntmax||(cntsum==cntmax&&yenrest<yenmin)){
				cntmax=cntsum;
				yenmin=yenrest;
				memcpy(ans,cnt,sizeof(ans));
			}
		}
		return;
	}
	for(i=0;i<=has[j];i++){
		cnt[j]=i;
		F(yenrest-i*unit[j],j-1,cntsum+i);
	}
}
main(){
	int i,yenrest,cr=0;
	for(;scanf("%d",&yenrest)*yenrest;){
		scanf("%d%d%d%d",has,has+1,has+2,has+3);
		cntmax=-99;
		yenmin=1e9;
		F(yenrest,3,0);
		if(cr)
			puts("");
		for(i=0;i<3;i++){
			if(ans[i])
				printf("%d %d\n",unit[i],ans[i]);
		}
		cr=1;
	}
}