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

struct kgrupa 
{
	char c[2];
	int br;
};

int main()
{
	int Od, Op, Ad,Ap, Bd, Bp, ABd, ABp, Od1, Ad1, Bd1, ABd1;
	int n;
	scanf("%d",&n);
	struct kgrupa a[n]; 
	int k = 0;
	int b[n][4];

	scanf("%d %d %d %d",&Od,&Ad,&Bd,&ABd);
	Od1 = Od;
	Ad1 = Ad;
	Bd1 = Bd;
	ABd1 = ABd;

	for(int i = 0; i < n; i++)
		scanf("%s %d",&a[i].c,&a[i].br);

	Op = 0;
	Ap = 0;
	Bp = 0;
	ABp = 0;
	for(int i = 0; i < n; i++)
	{
		if(a[i].c[0] == 'O' || a[i].c[0] == 'o')
			Op += a[i].br;

		if(a[i].c[0] == 'B' || a[i].c[0] == 'b')
			Bp += a[i].br;

		if(a[i].c[0] == 'A' || a[i].c[0] == 'a')
			if (a[i].c[1] == 'B' || a[i].c[1] == 'b')
				ABp += a[i].br;
			else
				Ap += a[i].br;
	}

	//printf("\n");
	if(Od - Op >= 0)
	{
		Od -= Op;
		k = 1;
	}
	else
	{
		k = 0;
		goto l;
	}

	if(Ad - Ap >= 0)
	{
		Ad -= Ap;
		k = 1;
	}
	else
		if((Ad + Od) - Ap >= 0)
		{
			Ad -= Ap;
			Od -= abs(Ad);
			if(Od < 0)
				Od = 0;
			Ad = 0;
			k = 1;
		}
		else
		{
			k = 0;
			goto l;
		}

	if(Bd - Bp >= 0)
	{
		Bd -= Bp;
		k = 1;
	}
	else
		if((Bd + Od) - Bp >= 0)
		{
			Bd -= Bp;
			Od -= abs(Bd);
			if(Od < 0)
				Od = 0;
			Bd = 0;
			
			k = 1;
		}
		else
		{
			 k = 0;
			goto l;	
		}

	if(ABd - ABp >= 0)
	{
		ABd -= ABp;
		k = 1;
	}
	else
		if((ABd + Od + Ad + Bd) - ABp >= 0)
		{

			ABd -= ABp;
			Bd -= abs(ABd);
			Ad -= abs(Bd);
			Od -= abs(Ad);
			if(Bd < 0)
				Bd = 0;
			if(Ad < 0)
				Ad = 0;
			if(Od < 0)
				Od = 0;
			ABd = 0;
			k = 1;
		}
		else
		{
			k = 0;
			goto l;
		}

	if(k == 1)
		printf("moguce");

	
	if(ABd < 0)
		ABd = 0;
	if(Ad < 0)
		Ad = 0;
	if(Bd < 0)
		Bd = 0;
	if(Od < 0)
		Od = 0;
	printf("\n");
	for(int i = 0; i < n; i++)
	{
		switch(tolower(a[i].c[0]))
		{
			case 'a': 
				if(tolower(a[i].c[1]) != 'b')
				{
					if(Ad1 >= a[i].br)
					{
						Ad1 -= a[i].br;
						printf("%d %d %d %d\n",0,a[i].br,0,0);
					}
					else
					{
						int p = Ad1;
						Ad1 -= a[i].br;
						Od1 -= abs(Ad1);
						if(Od1 < 0)
							Od1 = 0;

						printf("%d %d %d %d\n",abs(Ad1),p,0,0);
						if(Ad1 < 0)
							Ad1 = 0;
					}	
				}
				else
				{
					if(ABd1 >= a[i].br)
					{
						ABd1 -= a[i].br;
						printf("%d %d %d %d\n",0,0,0,a[i].br);
					}
					else
					{
						int p = ABd1;
						ABd1 -= a[i].br;
						Bd1 -= abs(ABd1);
						Ad1 -= abs(Bd1);
						Od1 -= abs(Ad1);

						printf("%d %d %d %d\n",abs(Ad1),abs(Bd1),abs(ABd1),p);
						ABd1 = 0;
						if(Bd1 < 0)
							Bd1 = 0;
						if(Ad1 < 0)
							Ad1 = 0;
						if(Od1 < 0)
							Od1 = 0;
					}	
				}

			break;

			case 'b': 
				if(Bd1 >= a[i].br)
				{
					Bd1 -= a[i].br;
					printf("%d %d %d %d\n",0,0,a[i].br,0);
				}
				else
				{
					int p = Bd1;
					Bd1 -= a[i].br;
					Od1 -= abs(Bd1);
					if(Od1 < 0)
						Od1 = 0;

					printf("%d %d %d %d\n",abs(Bd1),0,p,0);
					if(Bd1 < 0)
						Bd1 = 0;
				}
			break;

			case 'o': 
				Od1 -= a[i].br;
				printf("%d %d %d %d\n",a[i].br,0,0,0);
			break;
		}
	}

	l:
		if(k == 0)
			printf("nemoguce");

		/*printf("\n\n");
		for(int i = 0; i < n; i++)
			printf("%s-%d\n",a[i].c,a[i].br);

		printf("\n\nPacijenti:");
		printf("%d %d %d %d",Op,Ap,Bp,ABp);
		printf("\nDostupne:");
		printf("%d %d %d %d",Od,Ad,Bd,ABd);*/



	return 0;
}