#include <bits/stdc++.h>

using namespace std;

const int N = 10010;

long long ans[N][4];
pair<string, long long> x[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    long long n, o, a, b, ab;
    cin >> n >> o >> a >> b >> ab;
    for (int i = 0; i < n; i++) {
        cin >> x[i].first >> x[i].second;
    }
    for (int i = 0; i < n; i++) {
        if (x[i].first == "O") {
            long long temp = min(o, x[i].second);
            x[i].second -= temp;
            o -= temp;
            ans[i][0] += temp;
            if (x[i].second > 0) {
                cout << "nemoguce";
                return 0;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (x[i].first == "A") {
            long long temp = min(a, x[i].second);
            x[i].second -= temp;
            a -= temp;
            ans[i][1] += temp;

            temp = min(o, x[i].second);
            x[i].second -= temp;
            o -= temp;
            ans[i][0] += temp;
            if (x[i].second > 0) {
                cout << "nemoguce";
                return 0;
            }

        }
    }

    for (int i = 0; i < n; i++) {
        if (x[i].first == "B") {
            long long temp = min(b, x[i].second);
            x[i].second -= temp;
            b -= temp;
            ans[i][2] += temp;

            temp = min(o, x[i].second);
            x[i].second -= temp;
            o -= temp;
            ans[i][0] += temp;

            if (x[i].second > 0) {
                cout << "nemoguce";
                return 0;
            }

        }
    }

    for (int i = 0; i < n; i++) {
        if (x[i].first == "AB") {
            long long temp = min(ab, x[i].second);
            x[i].second -= temp;
            ab -= temp;
            ans[i][3] += temp;

            temp = min(b, x[i].second);
            x[i].second -= temp;
            b -= temp;
            ans[i][2] += temp;

            temp = min(a, x[i].second);
            x[i].second -= temp;
            a -= temp;
            ans[i][1] += temp;

            temp = min(o, x[i].second);
            x[i].second -= temp;
            o -= temp;
            ans[i][0] += temp;

            if (x[i].second > 0) {
                cout << "nemoguce";
                return 0;
            }

        }
    }
    cout << "moguce" << "\n";
    for (int i = 0; i < n; i++) {
        cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
    }

    return 0;
}