#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	int O, A, B, AB;
	cin >> O >> A >> B >> AB;
	vector<pair<string, int>> veci(n);
	vector<array<int, 4>> vec;

	unordered_map<string, int> mapi;
	mapi["O"] = 0;
	mapi["A"] = 1;
	mapi["B"] = 1;
	mapi["AB"] = 2;

	for (int i = 0; i < n; i++) {
		cin >> veci[i].first >> veci[i].second;
	}

	sort(veci.begin(), veci.end(), [&](const pair<string, int>& a, const pair<string, int>& b) {
		return (mapi[a.first] < mapi[b.first]) || ((mapi[a.first] == mapi[b.first]) && (a.second > b.second));
	});

	for (int i = 0; i < n; i++) {
		string grupa = veci[i].first;
		int kolicina = veci[i].second;
		if (grupa == "O") {
			if (O >= kolicina) {
				vec.push_back(array<int, 4>({kolicina, 0, 0, 0}));
				O -= kolicina;
			}
		}
		else if (grupa == "A") {
			if (A >= kolicina) {
				vec.push_back(array<int, 4>({0, kolicina, 0, 0}));
				A -= kolicina;
			}
			else {
				if (O >= (kolicina - A)) {
					vec.push_back(array<int, 4>({(kolicina - A), A, 0, 0}));
					O -= (kolicina - A);
					A = 0;
				}
				else {
					cout << "nemoguce" << endl;
					return 0;
				}
			}
		}
		else if (grupa == "B") {
			if (B >= kolicina) {
				vec.push_back(array<int, 4>({0, 0, kolicina, 0}));
				B -= kolicina;
			}
			else {
				if (O >= (kolicina - B)) {
					vec.push_back(array<int, 4>({(kolicina - B), 0, B, 0}));
					O -= (kolicina - B);
					B = 0;
				}
				else {
					cout << "nemoguce" << endl;
					return 0;
				}
			}
		}
		else if (grupa == "AB") {
			if (B > A) {
				array<int, 4> arr = {0, 0, 0, 0};
				int ab = min(kolicina, AB);
				arr[3] = ab;
				AB -= ab;
				kolicina -= ab;
				int b = min(kolicina, B);
				arr[2] = b;
				B -= b;
				kolicina -= b;
				int a = min(kolicina, A);
				arr[1] = a;
				A -= a;
				kolicina -= a;
				int o = min(kolicina, O);
				arr[0] = o;
				O -= o;
				kolicina -= o;
				if (kolicina > 0) {
					cout << "nemoguce" << endl;
					return 0;
				}
				vec.push_back(arr);
			}
			else {
				array<int, 4> arr = {0, 0, 0, 0};
				int ab = min(kolicina, AB);
				arr[3] = ab;
				AB -= ab;
				kolicina -= ab;
				int a = min(kolicina, A);
				arr[1] = a;
				A -= a;
				kolicina -= a;
				int b = min(kolicina, B);
				arr[2] = b;
				B -= b;
				kolicina -= b;
				int o = min(kolicina, O);
				arr[0] = o;
				O -= o;
				kolicina -= o;
				if (kolicina > 0) {
					cout << "nemoguce" << endl;
					return 0;
				}
				vec.push_back(arr);
			}
		}
	}

	cout << "moguce" << endl;
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i][0] << " " << vec[i][1] << " " << vec[i][2] << " " << vec[i][3] << endl;
	}
	return 0;
}