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

using namespace std;

int main()
{cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int t=1,op=0,ap=0,bp=0,abp=0,k[100000],c,i,n,a,b,ab,o,ar,br,opr,abr;
t=1;
cin>>n;
string s[100000];
cin>>o>>a>>b>>ab;
ar=a;
br=b;
abr=ab;
opr=o;
for(i=0;i<n;i++)
{
	cin>>s[i]>>k[i];
	if(s[i]=="A")
	ap=ap+k[i];
	if(s[i]=="B")
	bp=bp+k[i];
	if(s[i]=="AB")
	abp=abp+k[i];
	if(s[i]=="O")
	op=op+k[i];
}
if(op>o){t=0; }
o=o-op;
if(ap>a)
{
if(ap>a+o) {t=0; }
o=o-ap+a;
a=0;
}
a=a-ap;
if(bp>b)
{
if(bp>b+o) {t=0; }
o=o-bp+b;
b=0;
}
b=b-bp;
if(abp>a+o+b+ab){t=0; }
if(t==0)
{
	cout<<"nemoguce";
	return 0;
}
cout<<"moguce"<<endl;
for(i=0;i<n;i++)
{
	if(s[i]=="O")
	{
		cout<<k[i]<<" "<<0<<" "<<0<<" "<<0<<endl;
		opr=opr-k[i];
	}
	if(s[i]=="A")
	{
		cout<<max(0,k[i]-ar)<<" "<<min(k[i],ar)<<" "<<0<<" "<<0<<endl;
		
	}
		if(s[i]=="B")
	{
		cout<<max(0,k[i]-br)<<" "<<0<<" "<<min(k[i],br)<<" "<<0<<endl;
		
	}
			if(s[i]=="AB")
	{
		cout<<max(0,k[i]-abr-max(0,max(a,k[i]-abr))-max(0,max(a,k[i]-abr-max(0,max(a,k[i]-abr)))))<<" "<<max(0,max(a,k[i]-abr-max(0,max(a,k[i]-abr))))<<" "<<max(0,max(a,k[i]-abr))<<" "<<min(k[i],abr)<<endl;
		a=a-max(0,max(a,k[i]-abr));
		b=b-max(0,max(a,k[i]-abr-max(0,max(a,k[i]-abr))));
	}
}
}