#include <bits/stdc++.h>

using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first < b.first;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int p[4];
    for(int i = 0; i < 4; i++) cin >> p[i];
    pair<int, int> a[n];
    for(int i = 0; i < n; i++) {
    	string str;
    	cin >> str;
    	if(str == "0") a[i].first = 0;
    	else if(str == "A") a[i].first = 1;
    	else if(str == "B") a[i].first = 2;
    	else a[i].first = 3;
    	cin >> a[i].second;
    }
    sort(a, a+n, cmp);
    int b[n][4];
    for(int i = 0; i < n; i++) for(int j = 0; j < 4; j++) b[i][j] = 0;
    for(int i = 0; i < n; i++) {
		if(a[i].first == 0) {
			if(a[i].second <= p[0]) {
				p[0] -= a[i].second;
				b[i][0] += a[i].second;
			} else {
				cout << "nemoguce";
				return 0;
			}
		} else if(a[i].first == 1) {
			if(a[i].second <= p[1]) {
				p[1] -= a[i].second;
				b[i][1] += a[i].second;
			} else {
				b[i][1] += p[1];
				a[i].second -= p[1];
				p[1] = 0;
				if(a[i].second <= p[0]) {
					p[0] -= a[i].second;
					b[i][0] += a[i].second;
				} else {
					cout << "nemoguce";
					return 0;
				}
			}
		} else if(a[i].first == 2) {
			if(a[i].second <= p[2]) {
				p[2] -= a[i].second;
				b[i][2] += a[i].second;
			} else {
				b[i][2] += p[2];
				a[i].second -= p[2];
				p[2] = 0;
				if(a[i].second <= p[0]) {
					p[0] -= a[i].second;
					b[i][0] += a[i].second;
				} else {
					cout << "nemoguce";
					return 0;
				}
			}
		} else {
			for(int j = 0; j < 4; j++) {
				if(a[i].second <= p[j]) {
					p[j] -= a[i].second;
					b[i][j] += a[i].second;
					break;
				} else {
					if(j == 3) {
						cout << "nemoguce";
						return 0;
					}
					b[i][j] += p[j];
					a[i].second -= p[j];
					p[j] = 0;
				}
			}
		}
    }
    cout << "moguce\n";
    for(int i = 0; i < n; i++) {
    	for(int j = 0; j < 4; j++) cout << b[i][j] << " ";
    	cout << "\n";
    }
    return 0;
}