#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int m;
	int a,b,c,d;
	int sum;
	int tmp[4];
	int ans[4];
	
	while(1)
	{
		sum = 0;
		scanf("%d",&m);
		if(m==0)break;

		scanf("%d %d %d %d",&a,&b,&c,&d);
		
		sum += a*10+b*50+c*100+d*500;
		
		tmp[3] = (sum-m)/500;
		tmp[2] = (sum-m-tmp[3]*500)/100;
		tmp[1] = (sum-m-tmp[3]*500-tmp[2]*100)/50;
		tmp[0] = (sum-m-tmp[3]*500-tmp[2]*100-tmp[1]*50)/10;

		ans[0] = a - tmp[0];
		ans[1] = b - tmp[1];
		ans[2] = c - tmp[2];
		ans[3] = d - tmp[3];
		
			if(ans[0]>0){
			printf("10 %d\n",ans[0]);}
			if(ans[1]>0){
			printf("50 %d\n",ans[1]);}
			if(ans[2]>0){
			printf("100 %d\n",ans[2]);}
			if(ans[3]>0){
			printf("500 %d\n",ans[3]);}
			printf("\n");
	}
	return 0;
}
											