#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

struct Grupa {
	int o, a, b, ab;
};

void solve()
{
	int n;
	cin >> n;
	int o, a, b, ab;
	cin >> o >> a >> b >> ab;
	vector<Grupa> output(n);
	vector<int> special;
	bool flag = true;
	
	for (int i = 0; i < n; i++)
	{
		string group;
		cin >> group;
		int br;
		cin >> br;
		if (group == "O") {
			if (br > o) {
				flag = false;
			}
			else {
				output[i].o = br;
				o -= br;
			}
		}
		else if (group == "A") {
			if (br > (a + o)) {
				flag = false;
			}
			else
			{
				if (br > a) {
					output[i].a = a;
					output[i].o = (br - a);
					a = 0;
					o -= br;
				}
				else {
					output[i].a = br;
					a -= br;
				}
			}
		}
		else if (group == "B") {
			if (br > (b + o)) {
				flag = false;
			}
			else
			{
				if (br > b) {
					output[i].b = b;
					output[i].o = (br - b);
					b = 0;
					o -= br;
				}
				else {
					output[i].b = br;
					b -= br;
				}
			}
		}
		else {
			special.push_back(i);
			output[i].ab = br;
			continue;
		}
	}

	for (int i = 0; i < special.size(); i++)
	{
		int index = special[i];
		int br = output[index].ab;
		if (br > (ab + a + b + o)) {
			flag = false;
		}
		if (br > ab) {
			output[index].ab = ab;
			br -= ab;
			ab = 0;
			if (br > a) {
				output[index].a = a;
				br -= a;
				a = 0;
				if (br > b) {
					output[index].b = b;
					br -= b;
					b = 0;
					if (br > o) {
						flag = false;
					}
					else {
						output[index].o = br;
						o -= br;
					}
				}
				else {
					output[index].b = br;
					b -= br;
				}
			}
			else {
				output[index].a = br;
				a -= br;
			}
		}
		else {
			output[index].ab = br;
			ab -= br;
		}
	}
	
	if (flag) {
		cout << "moguce\n";
		for (int i = 0; i < n; i++)
		{
			cout << output[i].o << " " << output[i].a << " " << output[i].b << " " << output[i].ab << "\n";
		}
	}
	else {
		cout << "nemoguce\n";
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}