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

using namespace std;

int main()
{
	int i,j=0,po=0,pom=0,x,y,b,n;
    long int ro,ra,rb,rab;
	char g1,g2,g3,g4,c,c1,c2;
	char s[2];
	
	scanf("%d",&n);
	long int da[n],db[n],dog[n],dab[n],br,abr[n],abp[n];
	
	scanf("%d %d %d %d",&ro,&ra,&rb,&rab);
	
	i=0;
	while(i<n)
	{
		scanf("%s",&c);
		scanf("%d",&b);
		
		
		if(c=='O')
		{
			if(b>ro)
			{
				po=1;
			}
			else
			{
				dog[i]=b;
				da[i]=0;
				db[i]=0;
				dab[i]=0;

			}
		}
		
		else if(c=='A')
		{
			if(b<=ra)
			{
				ra=ra-b;
				dog[i]=0;
				da[i]=b;
				db[i]=0;
				dab[i]=0;
			}
			else if((ra+ro)>b)
			{
				pom=b-ra;
				da[i]=ra;
				ra=0;
				ro=ro-pom;
				dog[i]=pom;
				db[i]=0;
				dab[i]=0;
			}
			else if((ra+ro)<b)
			{
				po=1;
			}
		}
		
		else if(c=='B')
		{
			if(b<=rb)
			{
				rb=rb-b;
				dog[i]=0;
				db[i]=b;
				da[i]=0;
				dab[i]=0;
			}
			else if((rb+ro)>b)
			{
				pom=b-rb;
				db[i]=rb;
				rb=0;
				ro=ro-pom;
				dog[i]=pom;
				da[i]=0;
				dab[i]=0;
			}
			else if((rb+ro)<b)
			{
				po=1;
			}
		}
		
		else if(c=='AB')
		{
			abr[j]=i;
			abp[j]=b;
			j++;
		}
		
	i++;
	}
	
	
	i=0;
	while(i<j)
	{
		x=abr[i];
		y=abp[i];
		if(rab>y)
		{
			rab=rab-y;
			dog[x]=0;
			db[x]=0;
			da[x]=0;
			dab[x]=y;
			
		}
		if((rab+rb+ra+ro)>y)
		{
			dab[x]=rab;
			rab=0;
			
			if(rb>(y-dab[x]))
			{
				db[x]=y;
				rb=rb-y;
				dog[x]=0;
				da[x]=0;
			}
			if(rb<=(y-dab[x])&&rb!=0)
			{
				db[x]=rb;
				rb=0;
			}
			if(ra>(y-dab[x]-db[x])&&rab==0&&rb==0)
			{
				ra=ra-y-dab[x]-db[x];
				da[x]=y-dab[x]-db[x];
				dog[x]=0;
				
			}
			if(ra<=(y-dab[x]-db[x])&&rab==0&&rb==0)
			{
				da[x]=ra;
				ra=0;
			}
			if(ro>(y-dab[x]-db[x]-da[x])&&rab==0&&rb==0&&ra==0)
			{
				pom=y-ra-y-dab[x]-db[x];
				dog[x]=pom;
				ro=ro-dog[x];
			}
			if(ro<(y-dab[x]-db[x]-da[x])&&rab==0&&rb==0&&ra==0)
			{
				po=1;
			}
		}
		i++;
		
	}
	
	if(po==1)
	{
		printf("nemoguce");
	}
	else if(po!=1)
	{
		printf("moguce");
		for(i=0;i<n;i++)
			{
				printf("\n%d %d %d %d",dog[i],da[i],db[i],dab[i]);
			}
	}
	return 0;
}