#include <iostream>
#include <string>
using namespace std;
void rmel(string a[],int b[],int i,int *n){
	for(int j=i; j<*n-1; j++){
		a[j]=a[j+1];
		b[j]=b[j+1];
	}
	*n=*n-1;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	bool pos=true;
	static int anso[10000],ansa[10000],ansb[10000],ansab[10000];
	int n;
	int on,an,bn,abn;
	cin >> n;
	cin >> on >> an >> bn >> abn;
	string the1[10000];
	int the2[10000];
	for(int i=0; i < n; i++)
		cin >> the1[i] >> the2[i];
	int j=0;
	for(int i=0; i < n && pos; j++){
		if(the1[i]=="O"){
			on-=the2[i];
			if(on<0){
				pos=false;
				break;
			}
			anso[j]=the2[i];
			rmel(the1,the2,i,&n);
		}
		else i++;
	}
	for(int i=0, j=0; i < n && pos; j++){
		while(anso[j]) j++; 
		if(the1[i]=="A"){
			if(an>0){
				ansa[j]=min(an,the2[i]);
				int tmp=the2[i];
				the2[i]-=min(an,the2[i]);
				an-=min(an,tmp);
			}
			if(the2[i]!=0){
				if(on>=the2[i]){
					on-=the2[i];
					anso[j]=the2[i];
				}
				else{
					pos=false;
					break;
				}
			}
			rmel(the1,the2,i,&n);
		}
		else if(the1[i]=="B"){
			if(bn>0){
				ansb[j]=min(bn,the2[i]);
				int tmp=the2[i];
				the2[i]-=min(bn,the2[i]);
				bn-=min(bn,tmp);
			}
			if(the2[i]!=0){
				if(on>=the2[i]){
					on-=the2[i];
					anso[j]=the2[i];
				}
				else{
					pos=false;
					break;
				}
			}
			rmel(the1,the2,i,&n);
		}
		else i++;
	}
	for(int i=0, j=0; i < n && pos; j++, i++){
		while(anso[j]||ansb[j]||ansa[j]) j++;
		while(the2[i]!=0){
			if(abn>0){
				ansab[j]+=min(abn,the2[i]);
				int tmp=the2[i];
				the2[i]-=min(abn,the2[i]);
				abn-=min(abn,tmp);
			}
			else if(bn>0){
				ansb[j]+=min(bn,the2[i]);
				int tmp=the2[i];
				the2[i]-=min(bn,the2[i]);
				bn-=min(bn,tmp);
			}
			else if(an>0){
				ansa[j]+=min(an,the2[i]);
				int tmp=the2[i];
				the2[i]-=min(an,the2[i]);
				an-=min(an,tmp);
			}
			else if(on>0){
				anso[j]+=min(on,the2[i]);
				int tmp=the2[i];
				the2[i]-=min(on,the2[i]);
				on-=min(on,tmp);
			}
			else{
				pos=false;
				break;
			}
		}	
	}
	if(!pos) cout << "nemoguce\n";
	else{
		cout << "moguce\n";
		for(int i=0; i < j; i++)
			cout << anso[i] << " " << ansa[i] << " " << ansb[i] << " " << ansab[i] << "\n";
	}	
}