#include<iostream>

using namespace std;

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

int val[4] = {10,50,100,500}; 
int tmp[4],c[4],_min[4],minnum,now;
int main()
{
	int n;
	bool first = true;
	while(cin >> n,(n))
	{
		if(!first)cout << endl;
		first = false;
		minnum = 1000,now = 0;
		REP(i,4)
		{
			cin >> c[i];now += c[i];
			tmp[i] = 0;_min[i] = 100;
		}
		
		REP(i,c[0]+1)REP(j,c[1]+1)REP(k,c[2]+1)REP(l,c[3]+1)
		{
			int sum = 10 * i + 50 * j + 100 * k + 500 * l;
			if(sum < n)continue;
			int tmpnum = now-i-j-k-l,otu = sum - n;
			
			REP(a,4)
			{
				int num = otu / val[3-a];
				tmp[3-a] = num;
				otu -= num * val[3-a];
				tmpnum += num;
			}
			if(minnum > tmpnum)
			{
				minnum = tmpnum;
				_min[0] = i;
				_min[1] = j;
				_min[2] = k;
				_min[3] = l;
			}
			
		}
		
		REP(i,4)
		{
			if(_min[i]) cout << val[i] << ' ' << _min[i] << endl;
		}
		
	}
		
			
	
	return 0;
}
		