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

struct patient
{
	char type[2];
	int need;
	int taken[4];	
};

void setnul(int* arr, int n)
{
	for(int i = 0 ; i < n ; i++)
		arr[i] = 0;
}	

void rip()
{
	printf("nemoguce");
	exit(1);
}

int main() 	
{
	int n;
	scanf("%d", &n);
	struct patient patient[n];
	int o,a,b,ab;
	scanf("%d %d %d %d",&o,&a,&b,&ab);
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%s %d",&patient[i].type,&patient[i].need);
		setnul(patient[i].taken, 4);
	}

	for(int i = 0 ; i < n ; i++)
		if(strchr(patient[i].type, 'O') != NULL && patient[i].need <= o)
		{
			o-= patient[i].need;
			patient[i].taken[0] = patient[i].need;
		}
		else if(patient[i].need > o && strchr(patient[i].type, 'O') != NULL)
		rip();	
	
	for(int i = 0 ; i < n ; i++)
	{
		if(strchr(patient[i].type, 'A') != NULL && strstr(patient[i].type, "AB") == NULL)	
			if(a >= patient[i].need)
			{
				patient[i].taken[1] = patient[i].need;
				a-=patient[i].need;
			}
			else if(a + o >= patient[i].need)	
			{
				patient[i].taken[1] = a;
				patient[i].taken[0] = abs(a - patient[i].need);
				o+=(a - patient[i].need);
				a = 0;
			}
			else if(strchr(patient[i].type, 'A') != NULL && patient[i].need > (a + o) && strstr(patient[i].type, "AB") == NULL)
				rip();
		
		if(strchr(patient[i].type, 'B') != NULL && strstr(patient[i].type, "AB") == NULL)
			if(b >= patient[i].need)
			{
				patient[i].taken[2] = patient[i].need;
				b-=patient[i].need;
			}
			else if(b + o >= patient[i].need)
			{
				patient[i].taken[2] = b;
				patient[i].taken[0] = abs(b - patient[i].need);
				o+=(b - patient[i].need);
				b = 0;
			}
			else if(strchr(patient[i].type, 'B') != NULL && patient[i].need > (b + o) && strstr(patient[i].type, "AB") == NULL)
				rip();
	}

	int rest = o + a + b + ab;

	for(int i = 0 ; i < n ; i++)
		if(strstr(patient[i].type, "AB") != NULL)
			if(rest >= patient[i].need)
			{
				patient[i].taken[3] = ab;
				if(patient[i].need > patient[i].taken[3])
					patient[i].taken[0] = o;
				
				if(patient[i].need > patient[i].taken[3] + patient[i].taken[0])
					patient[i].taken[1] = a;
				
				if(patient[i].need > patient[i].taken[3] + patient[i].taken[0] + patient[i].taken[1])
					patient[i].taken[2] = b;

			}else if(strstr(patient[i].type, "AB") != NULL && rest < patient[i].need)
				rip();
	
	printf("moguce\n");
	for(int i = 0 ; i < n ; i++)
		printf("%d %d %d %d\n", patient[i].taken[0], patient[i].taken[1], patient[i].taken[2], patient[i].taken[3]);
	

	return 0;
}