#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, o, a, b, ab; 
	cin >> n>> o >> a >> b >> ab;
	vector<vector<int>> ans(n, vector<int>(4));
	vector<pair<string, int>> p(n);
	rep(i, n){
		cin>>p[i].first >> p[i].second;
	} 
	rep(i, n){
		if(p[i].first == "O"){
			if(o<p[i].second){
				cout<<"nemoguce";
				return 0;
			}
			o-=p[i].second;
			ans[i][0] +=p[i].second;
		}
	}
	rep(i, n){
		if(p[i].first == "A"){
			if(a<p[i].second){
				if(a!=0){
					ans[i][1] +=a;
					p[i].second-=a;
					a = 0;
				}
				if(o<p[i].second){
					cout<<"nemoguce";
					return 0;
				}
				o-=p[i].second;
				ans[i][0] +=p[i].second;
			}
			else{
				a-=p[i].second;
				ans[i][1] +=p[i].second;
			}
			
		}
	}
	rep(i, n){
		if(p[i].first == "B"){
			if(b<p[i].second){
				if(b!=0){
					ans[i][2] +=b;
					p[i].second-=b;
					b = 0;
				}
				if(o<p[i].second){
					cout<<"nemoguce";
					return 0;
				}
				o-=p[i].second;
				ans[i][0] +=p[i].second;
			}
			else{
				b-=p[i].second;
				ans[i][2] +=p[i].second;
			}
			
		}
	}
	rep(i, n){
		if(p[i].first == "AB"){
			if(ab<p[i].second){
				if(ab!=0){
					ans[i][3]+=ab;
					p[i].second-=ab;
					ab = 0;
				}
				if(a<p[i].second){
					if(a!=0){
						ans[i][1] +=a;
						p[i].second-=a;
						a = 0;
					}
				}
				else{
					a-=p[i].second;
					ans[i][1]+=p[i].second;
					continue;
				}
				if(b<p[i].second){
					if(b!=0){
						ans[i][2] +=b;
						p[i].second-=b;
						b = 0;
					}
				}
				else{
					b-=p[i].second;
					ans[i][2]+=p[i].second;
					continue;
				}
				if(o<p[i].second){
					cout<<"nemoguce";
					return 0;
				}
				o-=p[i].second;
				ans[i][0] +=p[i].second;
			}
			else{
				ab-=p[i].second;
				ans[i][3]+=p[i].second;
			}
		}
	}
	cout<<"moguce\n";
	rep(i,n){
		rep(j, 4) cout << ans[i][j]<<' ';
		cout << '\n';
	}
	return 0;
}