#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,o,a,b,ab;
	bool m=true;
	cin>>n>>o>>a>>b>>ab;
	string kg[n];
	int bj[n];
	int bjj[n][4];
	int zab=0;
	for(int i=0;i<n;i++)
	{
		bjj[i][0]=0;
		bjj[i][1]=0;
		bjj[i][2]=0;
		bjj[i][3]=0;
		cin>>kg[i]>>bj[i];
		if(kg[i]=="O")
		{
			if(bj[i]<=o)
			{
				o=o-bj[i];
				bjj[i][0]=bj[i];
			}
			else m=false;
		}
		else if(kg[i]=="A")
		{
			if(bj[i]<=a)
			{
				a=a-bj[i];
				bjj[i][1]=bj[i];
			}
			else
			{
				bj[i]=bj[i]-a;
				bjj[i][1]=a;
				a=0;
				if(bj[i]<=o)
				{
					o=o-bj[i];
					bjj[i][0]=bj[i];
				}
				else m=false;
			}
		}
		else if(kg[i]=="B")
		{
			if(bj[i]<=b)
			{
				b=b-bj[i];
				bjj[i][2]=bj[i];
			}
			else
			{
				bj[i]=bj[i]-b;
				bjj[i][2]=b;
				b=0;
				if(bj[i]<=o)
				{
					o=o-bj[i];
					bjj[i][0]=bj[i];
				}
				else m=false;
			}
		}
		else zab=zab+1;
	}
	if(m==true)
	{
		if(o+a+b+ab>=zab)
		{
			cout<<"moguce\n";
			for(int i=0;i<n;i++)
			{
				if(kg[i]=="AB")
				{
					if(bj[i]<=o)
					{
						o=o-bj[i];
						bjj[i][0]=bj[i];
					}
					else
					{
						bj[i]=bj[i]-o;
						bjj[i][0]=o;
						o=0;
						if(bj[i]<=a)
						{
							a=a-bj[i];
							bjj[i][1]=bj[i];
						}
						else
						{
							bj[i]=bj[i]-a;
							bjj[i][1]=a;
							a=0;
							if(bj[i]<=b)
							{
								b=b-bj[i];
								bjj[i][2]=bj[i];
							}
							else 
							{
								bj[i]=bj[i]-b;
								bjj[i][2]=b;
								b=0;
								ab=ab-bj[i];
								bjj[i][3]=bj[i];
							}
						}
					}	
				}
				cout<<bjj[i][0]<<" "<<bjj[i][1]<<" "<<bjj[i][2]<<" "<<bjj[i][3]<<"\n";
			}
		}
		else cout<<"nemoguce";
	}
	else cout<<"nemoguce";
	
	return 0;
}