#include<iostream>

using namespace std;

struct pacijent{

string krv;	
long long litri;	
	
};

long long potrebno[50000][4];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	long long AB,A,B,O;
	long long AB1=0,A1=0,B1=0,O1=0;
	long long n,i;

	cin >> n;
	pacijent x[n+1];
	cin >> O >> A >> B >> AB;
	long long AB2=AB,A2=A,B2=B,O2=O;
	for(i=0;i<n;i++){
	
	cin >> x[i].krv >> x[i].litri;	
		
		if(x[i].krv=="A")
		A1=A1+x[i].litri;
		if(x[i].krv=="B")
		B1=B1+x[i].litri;
		if(x[i].krv=="AB")
		AB1=AB1+x[i].litri;
		if(x[i].krv=="O")
		O1=O1+x[i].litri;
		
	}
	long long x1=0;
	
	O2=O2-O1;
	
	if(O2<0)
	x1=1;
	else{
	
	if(A1<=A2){
	A2=A2-A1;
	}
	else{
	A2=0;
	O2=O2-(A1-A2);	
  }
  
	if(B1<=B2){
	B2=B2-B1;
	}
	else{
	B2=0;
	O2=O2-(B1-B2);	
  }	
	if(O2<0){
	x1=1;
  }
	else{
	
	if(AB2+O2+B2+A2<AB1)	
	x1=1;	
		
  }
		
	}
	
	if(x1==1)
	{
	cout << "nemoguce";
  }
	else{
		// 0-O 1-A 2-B 3-AB
		cout << "moguce" << "\n";
		for(i=0;i<n;i++){
		
		if(x[i].krv=="O"){
			potrebno[i][0]=x[i].litri;
			O=O-x[i].litri;
		}
		
		if(x[i].krv=="A"){
			if(x[i].litri<=A){
			potrebno[i][1]=x[i].litri;
			A=A-x[i].litri;	
		  }
		  else{
		  potrebno[i][1]=A;
			O=O-(x[i].litri-A);
			potrebno[i][0]=x[i].litri-A;
			A=0;
		  }
	  } 
	
		
		if(x[i].krv=="B"){
			if(x[i].litri<=B){
			potrebno[i][2]=x[i].litri;
			B=B-x[i].litri;	
		  }
		  else{
		  potrebno[i][2]=B;
			O=O-(x[i].litri-B);
			potrebno[i][0]=x[i].litri-B;
			B=0;
		  }
		}
		
	  } 
		
		for(i=0;i<n;i++){	
		
		if(x[i].krv=="A" || x[i].krv=="B" || x[i].krv=="O")	
			cout << potrebno[i][0] << " " << potrebno[i][1] << " " << potrebno[i][2] << " " << potrebno[i][3] << '\n';
		else{
		
		if(x[i].litri<=AB){
		potrebno[i][3]=x[i].litri;
		AB=x[i].litri;
		}
		else{
		
	  		 if(x[i].litri<=AB+O){
				 potrebno[i][3]=AB;
				 potrebno[i][0]=x[i].litri-AB;
				 AB=0;
				 O=O-(x[i].litri-AB);
			   }
			   else{
			   
			   			if(x[i].litri<=AB+O+A){
			   			potrebno[i][3]=AB;
			   			potrebno[i][0]=O;
				 			potrebno[i][1]=x[i].litri-AB-O;
				 			AB=0;
				 			O=0;
				 			A=A-(x[i].litri-AB-O);

			   			}
			   			else{
			   			potrebno[i][3]=AB;
			   			potrebno[i][0]=O;
			   			potrebno[i][1]=A;
				 			potrebno[i][2]=x[i].litri-AB-O-A;
				 			AB=0;
				 			O=0;
				 			A=0;
				 			B=B-(x[i].litri-AB-O-A);
			   			
							 	
			   			}
				 	
			   }
		
		
			
		}
		cout << potrebno[i][0] << " " << potrebno[i][1] << " " << potrebno[i][2] << " " << potrebno[i][3] << '\n';  
	  }
			
			
		}
  }
		
		
		
	
	
	return 0;
}