#include <iostream>
#include <string>
#include <cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
	
	long int n;
	bool f=true;
	long int o,a,b,ab;
	int nule,aovi=0,beovi=0,abeovi=0;
	
	cin>>n;
	cin>>o>>a>>b>>ab;
	
	string cr[n];
	int br[n];
	int m[n][4];
	for(int i=0;i<n;i++){
		cin>>cr[i]>>br[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<4;j++){
			m[i][j]=0;
		}}
		
	for(int i=0;i<n;i++){
		
			if(cr[i]=="O"){
				m[i][0]=br[i];
				o=o-br[i];
				if(o<0) f=false;
			}else if(cr[i]=="A"){
				if(a>=br[i]){
					m[i][1]=br[i];
					a=a-br[i];
				}else{
					m[i][1]=a;
					br[i]=br[i]-a;
					a=0;
					m[i][0]=br[i];
					o=o-br[i];
					if(o<0) f=false;
				}
			}else if(cr[i]=="B"){
				if(b>=br[i]){
					m[i][2]=br[i];
					b=b-br[i];
					br[i]=0;
					
				}else{
					m[i][2]=b;
					br[i]=br[i]-b;
					b=0;
					m[i][0]=br[i];
					o=o-br[i];
					br[i]=0;
					if(o<0) f=false;
				}
			}else{
				if(ab>=br[i]){
					m[i][3]=br[i];
					ab=ab-br[i];
					br[i]=0;
				}else{
					m[i][3]=ab;
					br[i]=br[i]-ab;
					ab=0;
					if(b>=br[i]){
						m[i][2]=br[i];
						b=b-br[i];
						br[i]=0;
					}else {
						m[i][2]=b;
						br[i]=br[i]-b;
						b=0;
						if(a>=br[i]){
							m[i][1]=br[i];
							a=a-br[i];
							br[i]=0;
						}else{
							m[i][1]=a;
							br[i]=br[i]-a;
							a=0;
							m[i][0]=br[i];
							o=o-br[i];
							br[i]=0;
							if(o<0) f=false;
						}
					}
					
				}
			}
		
	}
	if(f==false) cout<<"nemoguce" ; else{
		cout<<"moguce"<<endl;
		for(int i=0;i<n;i++){
		for(int j=0;j<4;j++){
			cout<<m[i][j]<<" ";
		}
		cout<<endl;
		}
		
	}
	
	return 0;

	
}