#include <iostream>
#include <bits/stdc++.h>
#include <chrono>

using namespace std;

void solve()
{
	int n;
	vector<pair<int,int>> gr(4);
	cin >> n >> gr[0].first >> gr[1].first >> gr[2].first >> gr[3].first;
	vector<pair<int, int>> pac;
	for(int i = 0; i < n; i++) {
		string x;
		int y, z;
		cin >> x >> y;
		if(x == "O") {
			gr[0].second+= y;
			z = 0;
		}
		else if(x == "A"){
			gr[1].second+=y;
			z = 1;
		}
		else if(x == "B") {
			gr[2].second+=y;
			z = 2;
		}
		else {
			gr[3].second+=y;
			z = 3;
		}
		pac.push_back(make_pair(z,y));
	}
	if(gr[0].first >= gr[0].second && gr[1].second - gr[1].first <= gr[0].first - gr[0].second && gr[2].second - gr[2].second <= gr[0].first - gr[0].second && gr[1].second + gr[2].second - gr[1].first - gr[2].first <= gr[0].first - gr[0].second && gr[3].second - gr[3].first <= gr[0].first + gr[1].first +gr[2].first - gr[0].second - gr[1].second - gr[2].second) {
		printf("moguce\n");
		for(int i = 0; i < pac.size(); i++) {
			if(pac[i].first == 0) {
				gr[0].first -= pac[i].second; gr[0].second -= pac[i].second;
				printf("%d 0 0 0\n", pac[i].second);
			}
			else if(pac[i].first == 1) {
				if(gr[1].first - pac[i].second >= 0){
					printf("0 %d 0 0\n", pac[i].second);
					gr[1].first -= pac[i].second; gr[1].second -= pac[i].second;
				}
				else {
					printf("%d %d 0 0\n", pac[i].second - gr[1].first, gr[1].first);
					gr[0].first -= pac[i].second - gr[1].first;
					gr[1].second -= pac[i].second;
					gr[1].first = 0;
				}
			}
			else if(pac[i].first == 2) {
				if(gr[2].first - pac[i].second >= 0){
					printf("0 0 %d 0\n", pac[i].second);
					gr[2].first -= pac[i].second; gr[2].second -= pac[i].second;
				}
				else {
					printf("%d 0 %d 0\n", pac[i].second - gr[2].first, gr[2].first);
					gr[0].first -= pac[i].second - gr[2].first;
					gr[2].second -= pac[i].second;
					gr[2].first = 0;
				}
			}
			else {
				if(gr[3].first - pac[i].second >= 0) {
					printf("0 0 0 %d\n", pac[i].second);
					gr[3].first -= pac[i].second; gr[3].second -= pac[i].second;
				}
				else{
					int o = 0, a = 0, b = 0, ab = gr[3].first;
					pac[i].second -= gr[3].first;
					gr[3].first = 0;
					if(gr[1].first - gr[1].second >= pac[i].second){
						a = pac[i].second;
						pac[i].second = 0;
						gr[1].first -= a;
					}
					else {
						a = gr[1].first - gr[1].second;
						gr[1].first -= a;
						pac[i].second -= a;
					}
					if(gr[2].first - gr[2].second >= pac[i].second){
						b = pac[i].second;
						pac[i].second = 0;
						gr[2].first -= b;
					}
					else {
						b = gr[2].first - gr[2].second;
						gr[2].first -= b;
						pac[i].second -= b;
					}
					if(gr[0].first - gr[0].second >= pac[i].second){
						o = pac[i].second;
						pac[i].second = 0;
						gr[0].first -= o;
					}
					else {
						o = gr[0].first - gr[0].second;
						gr[0].first -= o;
						pac[i].second -= o;
					}
					printf("%d %d %d %d\n", o, a, b, ab);
				}
			}
		}
	}
	else printf("nemoguce");
}

int main(int argc, char** argv) {
	//auto start = std::chrono::high_resolution_clock::now();
	solve();
	//auto finish = std::chrono::high_resolution_clock::now();
	//std::chrono::duration<double> elapsed = finish - start;
	//std::cout << "\nElapsed time: " << elapsed.count() << " s\n";
	return 0;
}