#include <bits/stdc++.h>

using namespace std;

int res[10000][4];
vector<int> pa;

int main(){
	int n; cin>>n;
	int o,a,b,ab; cin>>o>>a>>b>>ab;
	bool moguce=true;
	int abp=0;
	for(int i=0;i<n;i++){
		string gr; int br;
		cin>>gr>>br;
		if(gr=="O" && o<br) moguce=false;
		else if(gr=="0" && o>=br){
			o-=br;
			res[i][0]=br;
		}
		if(gr=="A"){
			if(a>=br){
				a-=br;
				res[i][1]=br;
			}
			else{
				res[i][1]=a;
				a=0;
				br-=a;
				if(br>o) moguce=false;
				else{
					o-=br;
					res[i][0]=br;
				}
			}
		}
		if(gr=="B"){
			if(b>=br){
				b-=br;
				res[i][2]=br;
			}
			else{
				res[i][2]=b;
				b=0;
				br-=b;
				if(br>o) moguce=false;
				else{
					o-=br;
					res[i][0]=br;
				}
			}
		}
		if(gr=="AB"){
			abp+=br;
			pa.push_back(br);
			res[i][0]=-1;
		}
	}
	if(abp>o+a+b+ab) moguce=false;
	if(moguce==false) cout<<"nemoguce";
	else{
		cout<<"moguce\n";
		int ind=0;
		for(int i=0;i<n;i++){
			if(res[i][0]==-1){
				int pom=pa[ind];
				if(o>=pom){
					o-=pom;
					cout<<pom<<" 0 0 0\n";
				}else{
					cout<<o<<" ";
					pom-=o;
					if(a>=pom){
						a-=pom;
						cout<<pom<<" 0 0\n";
					}else{
						cout<<a<<" ";
						pom-=a;
						if(b>=pom){
							b-=pom;
							cout<<pom<<" 0\n";
						}else{
							cout<<b<<" ";
							pom-=b;
							cout<<pom<<"\n";
							ab-=pom;
						}
					}
				}
				ind++;
			}else{
				cout<<res[i][0]<<" "<<res[i][1]<<" "<<res[i][2]<<" "<<res[i][3]<<"\n";
			}
		}
	}
	return 0;
}