#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,pzO,pzA,pzB,pzAB,zO,zA,zB,zAB,kk[10000],pO=0,pA=0,pB=0,pAB=0,z,o,a,b,ab;
	string kg[10000];
	char p;
	cin>>n>>zO>>zA>>zB>>zAB;
	pzO=zO;
	pzA=zA;
	pzB=zB;
	pzAB=pzAB;
	for(int i=0;i<n;i++)
	{
		cin>>kg[i]>>kk[i];
	}
	for(int i=0;i<n;i++)
	{
		if(kg[i]=="O")
		pO+=kk[i];
		if(kg[i]=="A")
		pA+=kk[i];
		if(kg[i]=="B")
		pB+=kk[i];
		if(kg[i]=="AB")
		pAB+=kk[i];
	}
	z=zO+zA+zB+zAB;
	zO=zO-pO;
	if(zO<0)//da li zaliha za O zadovoljava potrebe za O
	{
		cout<<"nemoguce";
		return 0;
	}
	pO=0;
	pA=pA-zA;
	if(pA>0)//da li zaliha za A zadovoljava potrebe za A
	{
		zA=0;
		zO=zO-pA;
	}
	else
	{
		zA=zA-pA;
	}
	if(zO<0)
	{
		cout<<"nemoguce";
		return 0;
	}
	pA=0;
	pB=pB-zB;
	if(pB>0)
	{
		zB=0;
		zO=zO-pB;
	}
	else
	{
		zB=zB-pB;
	}
	pB=0;
	if(zO<0)
	{
		cout<<"nemoguce";
		return 0;
	}
	if(zO+zA+zB+zAB<pAB)
	{
		cout<<"nemoguce";
		return 0;
	}
	else
	cout<<"moguce\n";
	for(int i=0;i<n;i++)
	{
		if(kg[i]=="O")
		{
			o=kk[i];
			a=0;
			b=0;
			ab=0;
		}
		if(kg[i]=="A")
		{
			if(pzA>=kk[i])
			{
				o=0;
				a=kk[i];
			}
			else
			{
				a=pzA;
				o=kk[i]-a;
			}
			b=0;
			ab=0;
		}
		if(kg[i]=="B")
		{
			if(pzB>=kk[i])
			{
				b=kk[i];
				o=0;
			}
			else
			{
				b=pzB;
				o=kk[i]-b;
			}
			a=0;
			ab=0;
		}
		if(kg[i]=="AB")
		{
			if(zAB>=kk[i])
			{
				ab=kk[i];
				o=0;
				a=0;
				b=0;
				zAB-=ab;
			}
			else
			{
				ab=zAB;
				kk[i]-=ab;
				zAB=0;
				if(zO>=kk[i])
				{
					o=kk[i];
					a=0;
					b=0;
					zO-=o;
				}
				else
				{
					o=zO;
					kk[i]-=o;
					zO=0;
					if(zA>=kk[i])
					{
						a=kk[i];
						b=0;
						zA-=a;
					}
					else
					{
						a=zA;
						kk[i]-=a;
						zA=0;
						if(zB>=kk[i])
						{
							b=kk[i];
							zB-=b;
						}
						else
						{
							b=zB;
							kk[i]-=b;
							zB=0;
						}
					}
				}
			}
		}
		cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
		pzO-=o;
		pzA-=a;
		pzB-=b;
		pzAB-=ab;
	}
	return 0;
}