#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
   
   int n;
   cin>>n;
   
   int o,a,b,ab;
   cin>>o>>a>>b>>ab;
   int u=o+a+b+ab;
   int u1=0,o1=0,a1=0,b1=0,ab1=0;
   
   vector<pair<string,int> > krv(n);
     
   for(int i=0; i < n; i++)
   {
   		   cin>>krv[i].first;
 		   cin>>krv[i].second;
		    
   			u1+=krv[i].second;
   			if(krv[i].first=="O") 
			   {
			   	o1+=krv[i].second;
			   }
   			   else if(krv[i].first=="A")
   			   {
   			   	a1+=krv[i].second;
			   	 	}
			   	 	 else if(krv[i].first=="B")
   			   {
   			   	b1+=krv[i].second;
			   	 	}
			   	 	 else if(krv[i].first=="AB")
   			   {
   			   	ab1+=krv[i].second;
			   	 	}
   }
 
 int moguce=0;
 
   if(u1>u || o1>o ) cout<<"nemoguce";
   else{
		o=o-o1;
	
   		if(a1>a)
   		{
   		 	if(a1>=(a+o)) moguce=1; 
	  		else 
			  {
			   	 o=o+a-a1; 
			   	 
			  }
		} 
	   
   	   
     
   		if(b1>b)
   		{
   		 	if(b1>=(b+o)) moguce=1;
   			else 
			   {
			   	o=o+b-b1;
	
			   }
		}
		
		if(moguce==1) cout<<"nemoguce";
		else
		{
			cout<<"moguce";
			cout<<endl;
			for(int i=0;i<n;i++)
			{
				if(krv[i].first=="O") 
				{
					cout<<krv[i].second<<" "<<0<<" "<<0<<" "<<0;
					cout<<endl;
				}
				if(krv[i].first=="A")
				{
					if(krv[i].second<=a){
					 cout<<0<<" "<<krv[i].second<<" "<<0<<" "<<0;
					 a=a-krv[i].second;
					 }
					else {
						cout<<krv[i].second-a<<" "<<a<<" "<<0<<" "<<0;
						a=0;
					}
					cout<<endl;
					
				}
				if(krv[i].first=="B")
				{
			  	    if(krv[i].second<=b) {
					  cout<<0<<" "<<0<<" "<<krv[i].second<<" "<<0;
					  b=b-krv[i].second;
					  }
					else {
					cout<<krv[i].second-b<<" "<<0<<" "<<b<<" "<<0;
					b=0;
					}
					cout<<endl;
				}
				if(krv[i].first=="AB")
				{
					if(krv[i].second<=ab)  cout<<0<<" "<<0<<" "<<0<<" "<<krv[i].second;
					else
					{
						if(a>=krv[i].second-ab) cout<<0<<" "<<krv[i].second-ab<<" "<<0<<" "<<ab;
						else if(b>=krv[i].second-ab) cout<<0<<" "<<0<<" "<<krv[i].second-ab<<" "<<ab;
						else if(o>=krv[i].second-ab) cout<<krv[i].second-ab<<" "<<0<<" "<<0<<" "<<ab;
						else
						{
							if(a>=krv[i].second-o-ab)
							cout<<o<<" "<<krv[i].second-o-ab<<" "<<0<<" "<<ab;
							else
							cout<<o<<" "<<a<<" "<<krv[i].second-o-ab-a<<" "<<ab;
							
						}
					}
					cout<<endl;
					
				}
			}
		}
   	
   }

	
	return 0;
}