#include <iostream>
#include <vector>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

struct krv{
	string g;
	int br;
};

struct kon{
	int O,A,B,AB;
};

vector<kon> res;

void ispis(){
	for(int i=0;i<res.size();i++){
		cout<<res[i].O<<" "<<res[i].A<<" "<<res[i].B<<" "<<res[i].AB<<endl;
	}
}


int main(int argc, char** argv) {
	long long n;
	long long o,a,b,c;
	vector<krv> v;
	cin>>n;
	cin>>o>>a>>b>>c;
	
	string grupa;
	int broj;
	for(int i=0;i<n;i++){
		cin>>grupa>>broj;
		krv k;
		k.g=grupa;
		k.br=broj;
		v.push_back(k);
	}
	kon p;
	for(int i=0;i<n;i++){
		res.push_back(p);
	}
	//grupa O
	for(int i=0;i<n;i++){
		if(v[i].g=="O"){
			if(o>=v[i].br){
				res[i].O=v[i].br;
				o-=v[i].br;
				res[i].A=0;
				res[i].B=0;
				res[i].AB=0;
			}
			else{
				cout<<"nemoguce";
				return 0;
			}
		}
	}
	//grupa A
	for(int i=0;i<n;i++){
		if(v[i].g=="A"){
			if(a>0){
				if(a>=v[i].br){
					res[i].A=v[i].br;
					a-=v[i].br;
					res[i].O=0;
					res[i].B=0;
					res[i].AB=0;
				}
				else{
					res[i].A=a;
					v[i].br-=a;
					a=0;
					if(o>=v[i].br){
						o-=v[i].br;
						res[i].O=v[i].br;
					}
					else{
						cout<<"nemoguce";
						return 0;
					}
					res[i].B=0;
					res[i].AB=0;
				}
			}
			else if(o>=v[i].br){
				res[i].O=v[i].br;
				o-=v[i].br;
				res[i].A=0;
				res[i].B=0;
				res[i].AB=0;
			}
			else{
				cout<<"nemoguce";
				return 0;
			}
		}
	}
	//grupa B
	for(int i=0;i<n;i++){
		if(v[i].g=="B"){
			if(b>0){
				if(b>=v[i].br){
					res[i].B=v[i].br;
					b-=v[i].br;
					res[i].O=0;
					res[i].A=0;
					res[i].AB=0;
				}
				else{
					res[i].B=b;
					v[i].br-=b;
					b=0;
					if(o>=v[i].br){
						o-=v[i].br;
						res[i].O=v[i].br;
					}
					else{
						cout<<"nemoguce";
						return 0;
					}
					res[i].A=0;
					res[i].AB=0;
				}
			}
			else if(o>=v[i].br){
				res[i].O=v[i].br;
				o-=v[i].br;
				res[i].A=0;
				res[i].B=0;
				res[i].AB=0;
			}
			else{
				cout<<"nemoguce";
				return 0;
			}
		}
	}
	//GRUPA AB
	for(int i=0;i<n;i++){
		if(v[i].g=="AB"){
			if(c>=v[i].br){
				res[i].AB=v[i].br;
				c-=res[i].AB;
				res[i].A=0;
				res[i].B=0;
				res[i].O=0;
			}
			else{
				res[i].AB=c;
				v[i].br-=c;
				c=0;
				if(a>=v[i].br){
					res[i].A=v[i].br;
					a-=v[i].br;
					res[i].B=0;
					res[i].O=0;
				}
				else{
					res[i].A=a;
					v[i].br-=a;
					a=0;
					if(b>=v[i].br){
						res[i].B=v[i].br;
						b-=v[i].br;
						res[i].O=0;
					}
					else{
						res[i].B=b;
						v[i].br-=b;
						b=0;
						cout<<o<<endl;
						if(o>=v[i].br){
							res[i].O=v[i].br;
							o-=v[i].br;
						}
						else{
							cout<<"nemoguce";
							return 0;
						}
					}
				}
			}
		}
	}
	cout<<"moguce"<<endl;
	ispis();
	
	return 0;
}

/*
6
6
1
3
2
A
2
AB
3
O
1
AB
2
B
2
O
2
*/