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

int main(){
	int N, o, a, b, ab;
	string boiA="A", boiB="B", boiO="O", boiAB="AB";
	string boi;
	cin>>N;
	cout<<endl;
	cin>>o>>a>>b>>ab;
	int jhin[N][2];
	int thresh[N][4];
	int p=1;
	for(int i=0;i<N;i++){
		for(int j=0;j<4;j++){
			thresh[i][j]=0;
		}
	}
	for(int i=0;i<N;i++){
		cin>>boi>>jhin[i][1];
		if(boiO==boi) jhin[i][0]=1;
		else if(boiA==boi) jhin[i][0]=2;
		else if(boiB==boi) jhin[i][0]=3;
		else if(boiAB==boi) jhin[i][0]=4;		
	}
	for(int i=0;i<N;i++){
		if(p!=0){
			if(jhin[i][0]==1){
				if(o>=jhin[i][1]){
					o-=jhin[i][1];
					thresh[i][0]=jhin[i][1];
					jhin[i][1]=0;
				}
			else{
				p=0;
				cout<<"nemoguce"<<endl;
			}
			}
		}
		
	}

	
	for(int i=0;i<N;i++){
		if(p!=0){
			if(jhin[i][0]==2){
				if(a>=jhin[i][1]){
					a-=jhin[i][1];
					thresh[i][1]=jhin[i][1];
					jhin[i][1]=0;
				}
			else{
				jhin[i][1]-=a;
				thresh[i][1]=a;
				a=0;
				if(o>=jhin[i][1]){
					o-=jhin[i][1];
					thresh[i][0]=jhin[i][1];
					jhin[i][1]=0;
				}
				else{
					p=0;
					cout<<"nemoguce";
				}
			}
			}
		}
	}
		for(int i=0;i<N;i++){
			if(p!=0){
			if(jhin[i][0]==3){
				if(b>=jhin[i][1]){
					b-=jhin[i][1];
					thresh[i][2]=jhin[i][1];
					jhin[i][1]=0;
				}
				else{
					jhin[i][1]-=b;
					thresh[i][2]=b;
					b=0;
					
					if(o>=jhin[i][1]){
						o-=jhin[i][1];
						thresh[i][0]=jhin[i][1];
						jhin[i][1]=0;
					}
					else{
						p=0;
						cout<<"nemoguce";
					}
				}
			}
		}
	}

		for(int i=0;i<N;i++){
			if(p!=0){
			if(jhin[i][0]==4){
				if(ab>=jhin[i][1]){
					ab-=jhin[i][1];
					thresh[i][3]=jhin[i][1];
					jhin[i][1]=0;
				}
			else{
				jhin[i][1]-=ab;
				thresh[i][3]=ab;
				ab=0;
				if(b>=jhin[i][1]){
					b-=jhin[i][1];
					thresh[i][2]=jhin[i][1];
					jhin[i][1]=0;
				}
				else{
					jhin[i][1]-=b;
					thresh[i][2]=b;
					b=0;
					if(a>=jhin[i][1]){
						a-=jhin[i][1];
						thresh[i][1]=jhin[i][1];
						jhin[i][1]=0;
					}
					else{
						jhin[i][1]-=a;
						thresh[i][1]=a;
						a=0;
						if(o>=jhin[i][1]){
							o-=jhin[i][1];
							thresh[i][0]=jhin[i][1];
							jhin[i][1]=0;
						}
						else{
							p=0;
							cout<<"nemoguce";
						}
					}
				}
			}
		}
	}
}
	if(p!=0){
		cout<<"moguce"<<endl;
		for(int i=0;i<N;i++){
			for(int j=0;j<4;j++){
				cout<<thresh[i][j]<<" "; 
			}
			cout<<endl;
		}
	}	
			return 0;
}