#include<bits/stdc++.h>

using namespace std;

#define maxn 10005

int hesh[maxn];
int jedinice[maxn];

int moguce(int o, int a, int b, int ab, int po, int pa, int pb, int pab){
	if(po > o){
		return 0;
	}
	else{
		o = o - po;
	}
	if(pa > a + o){
		return 0;
	}
	else{
		a = a - pa;
		if(a < 0){
			o = o + a;
			a = 0;
		}
	}
	if(pb > b + o){
		return 0;
	}
	else{
		b = b - pb;
		if(b < 0){
			o = o + b;
			b = o;
		}
	}
	if(pab > o + a + b + ab){
		return 0;
	}
	else{
		return 1;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n, k;
	cin >> n;
	int o, a, b, ab;
	cin >> o >> a >> b >> ab;
	int po, pa, pb, pab;
	po = 0; pa = 0; pb = 0; pab = 0;
	string s;
	int pocetno;
	
	int x, y, z, m;
	int so, sa, sb;
	
	for(int i=0; i<n; i++){
		cin >> s >> k;
		if(s == "O") {
			po+=k;
			hesh[i] = 0;
			jedinice[i] = k;
		}
		else if(s == "A"){
			pa+=k;
			hesh[i] = 1;
			jedinice[i] = k;
		}
		else if(s == "B"){
			pb+=k;
			hesh[i] = 2;
			jedinice[i] = k;
		}
		else{
			pab+=k;
			hesh[i] = 3;
			jedinice[i] = k;
		}
	}
	
	int pivot = moguce (o, a, b, ab, po, pa, pb, pab);
	
	if(pivot == 0){
		cout << "nemoguce";
	}
	else{
		cout << "moguce" << endl;
		for(int i=0; i<n; i++){
			if(hesh[i]==0){
				po = po - jedinice[i];
				cout << jedinice[i] << " 0 0 0" << endl;
				o = o - jedinice[i];
			}
			else if(hesh[i]==1){
				pa = pa - jedinice[i];
				if(jedinice[i] < a){
					cout << "0 " << jedinice[i] << " 0 0" << endl;
					a = a - jedinice[i];
				}
				else{
					cout << jedinice[i] - a << " " << a << " 0 0" << endl;
					o = o - jedinice[i] + a;
					a = 0;
				}
			}
			else if(hesh[i]==2){
				pb = pb - jedinice[i];
				if(jedinice[i] < b){
					cout << "0 0 " << jedinice[i] << " 0" << endl;
					b = b - jedinice[i];
				}
				else{
					cout << jedinice[i] - b << " 0 " << b << " 0" << endl;
					o = o - jedinice[i] + b;
					b = 0;
				}
			}
			else{
				pab = pab - jedinice[i];
				if(jedinice[i] < ab){
					cout << "0 0 0 " << ab << endl;
					ab = ab - jedinice[i];
				}
				else{
					pocetno = jedinice[i];
					x = 0; y = 0; z = 0; m = 0;
					m = ab;
					jedinice[i] = jedinice[i] - ab;
					ab = 0;
					sa = max(0, a - pa);
					if(sa > 0){
						if(sa > jedinice[i]){
							a = a - jedinice[i];
							x = 0; y = jedinice[i]; z = 0;
							goto stop;
						}
						else{
							y = sa;
							a = a - sa;
							jedinice[i] = jedinice[i] - sa;
						}
					}
					sb = max(0, b - pb);
					if(sb > 0){
						if(sb > jedinice[i]){
							b = b - jedinice[i];
							x = 0; z = jedinice[i]; 
							goto stop;
						}
						else{
							z = sb;
							b = b - sb;
							jedinice[i] = jedinice[i] - sa;
						}
					}
					x = pocetno - y - z - m;
					stop: cout << x << " " << y << " " << z << " " << m << endl;
				}
			}
		}
	}
	
	return 0;
}