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

int main()
{
	int n,p,br=0,br2=0;
	int O,A,B,AB,O1,A1,B1,AB1,Apo,Opo,Bpo,ABpo;
	char key[1];
	
	scanf("%d",&n);
	
	int a[n],o[n],b[n],ab[n];
	a[0]=0;
	o[0]=0;
	b[0]=0;
	ab[0]=0;
	
	int br1=0;
	
	scanf("%d %d %d %d",&O,&A,&B,&AB);
	
	while(br1<n)
	{
		scanf("%s",key);
		if(strcmp(key,"AB")!=0)
		{
			switch(key[0])
	        {
	    	case 'A':
	    		{
	    			scanf("%d",&A1);
	    			if(A+O>=A1)
					{
						Apo=A;
						A=A-A1;
						if(A>=0)
						{
							a[br]=A1;
							b[br]=0;
							ab[br]=0;
							o[br]=0;
							break;
						}
						else
						{
							a[br]=Apo;
							A1=A1-Apo;
							O=O-A1;
							o[br]=A1;
							b[br]=0;
							ab[br]=0;
							break;
						}
        			}
					else
					{
						br1=n;
						br2=1;
						break;
					} 	    			
				}
	    	case 'B':
	    		{
	    			scanf("%d",&B1);
	    			if(B>=B1)
	    			{
	    				B=B-B1;
	    				ab[br]=0;
				    	o[br]=0;
						a[br]=0;
						b[br]=B1;
						break;
					}
					else if(B+O>=B1)
					{
						B1=B1-B;
						O=O-B1;
						ab[br]=0;
				    	o[br]=B1;
						a[br]=0;
						b[br]=B;
						break;
					}
					else
					{
						br1=n;
						br2=1;
						break;
					}
				}
			case 'O':
				{
					scanf("%d",&O1);
					if(O>=O1)
					{
						O=O-O1;
						o[br]=O1;
						ab[br]=0;
						a[br]=0;
						b[br]=0;
					}
					else
					{
						br1=n;
						br2=1;
						break;
					}
				}
	        }
		}
		else
		{
			scanf("%d",&AB1);
				    if(AB>=AB1)
				    {
				    	AB=AB-AB1;
				    	ab[br]=AB1;
				    	o[br]=0;
						a[br]=0;
						b[br]=0;
					}
					else if(AB+O>=AB1)
					{
						AB1=AB1-AB;
						O=O-AB1;
						ab[br]=AB;
				    	o[br]=AB1;
						a[br]=0;
						b[br]=0;
						AB=0;
					}
					else if(AB+O+A>=AB1)
					{
						AB1=AB1-AB;
						AB1=AB1-O;
						A=A-AB1;
						ab[br]=AB;
				    	o[br]=O;
						a[br]=AB1;
						b[br]=0;
					}
					else if(AB+O+A+B>=AB1)
					{
						AB1=AB1-AB;
						AB1=AB1-O;
						AB1=AB1-A;
						B=B-AB1;
						ab[br]=AB;
				    	o[br]=O;
						a[br]=A;
						b[br]=AB1;
					}
					else
					{
				    br1=n;
				    br2=1;
			        }
		}	
	    br=br+1;
	    br1=br1+1;
    }
	int i;
	
	if(br2<=0)
	{
		printf("\nmoguce");
		for(i=0;i<br;i++)
	    {
		    printf("\n%d %d %d %d",o[i],a[i],b[i],ab[i]);
	    }
	}
	else
	{
		printf("\nnemoguce");
	}
	
	scanf("%d",&p);
	return 0;
}