#include <bits/stdc++.h>

using namespace std;


int main(int argc, char** argv) 
{
	long long n;
	cin>>n;
	queue <string> red;
	stack <long long> o;
	stack <long long> a;
	stack <long long> b;
	stack <long long> ab;
	
	long long on, an, bn, abn, ok = 0, ak = 0, bk = 0, abk = 0, temp;
	cin>>on>>an>>bn>>abn;

	
	
	for(long long i=0; i<n; i++)
	{
	string str;
	long long d;
	cin>>str>>d;
	red.push(str);
	if(str == "O") {o.push(d); ok++;}
	if(str == "A") {a.push(d); ak++;}
	if(str == "B") {b.push(d); bk++;}
	if(str == "AB"){ab.push(d); abk++;}
	
	}
	long long om [ok][4];
	temp = ok;
	while(!o.empty())
	{
	if(on >= o.top())
		{
		on -= o.top();
		om[ok-1][0] = o.top();
		om[ok-1][1] = 0;
		om[ok-1][2] = 0;
		om[ok-1][3] = 0;
		o.pop();
		ok--;	
		}		
	else {cout<<"nemoguce"; return 0;}
	}
	ok = temp;
	temp = ak;
	long long am [ak][4];
	while(!a.empty())
	{
	if(on + an >= a.top())
		{
		if(an >= a.top()) {an-=a.top(); am[ak-1][0] = 0; am[ak -1][1] = a.top();}
		else 
		{
		am[ak-1][1] = an;	
		an -= a.top();
		am[ak-1][0] = -1* an;
		
		on += an;	
		an = 0;
		}
		am[ak-1][2] = 0;
		am[ak-1][3] = 0;
		a.pop();	
		ak--;
		}		
	else {cout<<"nemoguce";  return 0;}
	}
	
	ak = temp;
	temp = bk;
	long long bm [bk][4];
	
	
	
	while(!b.empty())
	{
	if(on + bn >= b.top())
		{
		if(bn >= b.top()) {bn-=b.top(); bm[bk-1][0] = 0; bm[bk -1][2] = b.top();}
		else 
		{
		bm[bk-1][2] = bn;	
		bn -= b.top();
		bm[bk-1][0] = -1* bn;
		
		on += bn;	
		bn = 0;
		}
		bm[bk-1][1] = 0;
		bm[bk-1][3] = 0;
		b.pop();	
		bk--;
		}		
	else {cout<<"nemoguce";  return 0;}
	}
	
	
	bk = temp;
	temp = abk;
	long long abm [abk][4];
	
	
	long long z;

	
	
	while(!ab.empty())
	{
	z = on + an + bn + abn;
	if(z >= ab.top())
		{
		if(abn>=ab.top())
		{
		abm[abk - 1][3] = ab.top();
		abm[abk - 1][2] = 0;
		abm[abk - 1][1] = 0;
		abm[abk - 1][0] = 0;
		abn-=ab.top();	
		}
		
		else if(bn>=ab.top())
		{
		abm[abk - 1][2] = ab.top();
		abm[abk - 1][3] = 0;
		abm[abk - 1][1] = 0;
		abm[abk - 1][0] = 0;
		bn -=ab.top();	
		}
		
		else if(an>=ab.top())
		{
		abm[abk - 1][1] = ab.top();
		abm[abk - 1][2] = 0;
		abm[abk - 1][3] = 0;
		abm[abk - 1][0] = 0;
		an -=ab.top();	
		}
		
		else if(on>=ab.top())
		{
		abm[abk - 1][0] = ab.top();
		abm[abk - 1][2] = 0;
		abm[abk - 1][1] = 0;
		abm[abk - 1][3] = 0;
		on -=ab.top();	
		}
		
		else if(bn+abn>=ab.top())
		{
		abm[abk - 1][3] = abn;
		ab.top() -=abn;
		abn = 0;
		abm[abk - 1][2] = ab.top();
		abm[abk - 1][1] = 0;
		abm[abk - 1][0] = 0;
		bn -=ab.top();	
		}
		
		else if(an+abn>=ab.top())
		{
		abm[abk - 1][3] = abn;
		ab.top() -=abn;
		abn = 0;
		abm[abk - 1][2] = 0;
		abm[abk - 1][1] = ab.top();
		abm[abk - 1][0] = 0;
		an -=ab.top();	
		}
		
		else if(on+abn>=ab.top())
		{
		abm[abk - 1][3] = abn;
		ab.top() -=abn;
		abn = 0;
		abm[abk - 1][2] = 0;
		abm[abk - 1][1] = 0;
		abm[abk - 1][0] = ab.top();
		on -=ab.top();	
		}
		
		else if(an+bn>=ab.top())
		{
		abm[abk - 1][2] = bn;
		ab.top() -=bn;
		bn = 0;
		abm[abk - 1][3] = 0;
		abm[abk - 1][1] = ab.top();
		abm[abk - 1][0] = 0;
		an -=ab.top();	
		}
		
		else if(on+bn>=ab.top())
		{
		abm[abk - 1][2] = bn;
		ab.top() -=bn;
		bn = 0;
		abm[abk - 1][3] = 0;
		abm[abk - 1][0] = ab.top();
		abm[abk - 1][1] = 0;
		on -=ab.top();	
		}
		
		else if(an+on>=ab.top())
		{
		abm[abk - 1][0] = on;
		ab.top() - on;
		on = 0;
		abm[abk - 1][3] = 0;
		abm[abk - 1][1] = ab.top();
		abm[abk - 1][2] = 0;
		an -=ab.top();	
		}
		
		else if(bn+abn + an>=ab.top())
		{
		abm[abk - 1][3] = abn;
		ab.top() -=abn;
		abn = 0;
		abm[abk - 1][2] = bn;
		ab.top() -= bn;
		bn = 0;
		abm[abk - 1][1] = ab.top();
		abm[abk - 1][0] = 0;
		an -=ab.top();	
		}
		
		else if(bn+abn + on>=ab.top())
		{
		abm[abk - 1][3] = abn;
		ab.top() -=abn;
		abn = 0;
		abm[abk - 1][2] = bn;
		ab.top() -= bn;
		bn = 0;
		abm[abk - 1][0] = ab.top();
		abm[abk - 1][1] = 0;
		on -=ab.top();	
		}
		
		else if(on+abn + an>=ab.top())
		{
		abm[abk - 1][3] = abn;
		ab.top() -=abn;
		abn = 0;
		abm[abk - 1][1] = an;
		ab.top() -= an;
		an = 0;
		abm[abk - 1][0] = ab.top();
		abm[abk - 1][2] = 0;
		on -=ab.top();	
		}
		
		else if(on+ bn + an>=ab.top())
		{
		abm[abk - 1][2] = bn;
		ab.top() -= bn;
		bn = 0;
		abm[abk - 1][1] = an;
		ab.top() -= an;
		an = 0;
		abm[abk - 1][0] = ab.top();
		abm[abk - 1][3] = 0;
		on -=ab.top();	
		}
		
		else
		{
		abm[abk - 1][3] = abn;
		ab.top() -=abn;
		abn = 0;
		abm[abk - 1][1] = an;
		ab.top() -= an;
		an = 0;
		abm[abk - 1][0] = on;
		ab.top() -= on;
		on = 0;
		abm[abk - 1][2] = ab.top();
		bn -=ab.top();	
		}
		
		ab.pop();	
		abk--;
		}		
	else {cout<<"nemoguce";  return 0;}
	}
	
	abk = temp;
	cout<<"moguce"<<endl;
	on = 0 ; an = 0; bn = 0; abn = 0;
	while(!red.empty())
	{
	if(red.front() == "O")	
		{
		cout<<om[on][0]<<" "<<om[on][1]<<" "<<om[on][2]<<" "<<om[on][3]<<endl;
		on++;	
		}
	if(red.front() == "A")	
		{
		cout<<am[an][0]<<" "<<am[an][1]<<" "<<am[an][2]<<" "<<am[an][3]<<endl;
		an++;	
		}
	if(red.front() == "B")	
		{
		cout<<bm[bn][0]<<" "<<bm[bn][1]<<" "<<bm[bn][2]<<" "<<bm[bn][3]<<endl;
		bn++;	
		}
	if(red.front() == "AB")	
		{
		cout<<abm[abn][0]<<" "<<abm[abn][1]<<" "<<abm[abn][2]<<" "<<abm[abn][3]<<endl;
		abn++;	
		}
			
	red.pop();	
	}
	
	
	
	return 0;
	
	
	
	
}