#include <bits/stdc++.h>

using namespace std;

const int O = 0, A = 1, B = 2, AB = 3;

int index(string s) {

    if(s == "O")
        return O;
    if(s == "A")
        return A;
    if(s == "B")
        return B;
    return AB;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    int cnt[4], cnt_copy[4];
    for(int i = 0; i < 4; i++) {
        cin >> cnt[i];
        cnt_copy[i] = cnt[i];
    }
    
    int missing[4];
    string s[n];
    int x[n];
    for(int i = 0; i < n; i++) {
        cin >> s[i] >> x[i];

        missing[index(s[i])] += x[i];
    }

    // O
    if(missing[O] > cnt[O]) {
        cout << "nemoguce" << endl;
        return 0;
    } else cnt[O] -= missing[O];

    // A
    if(missing[A] > cnt[A] + cnt[O]) {
        cout << "nemoguce" << endl;
        return 0;
    } else if(missing[A] > cnt[A]) {
        cnt[O] -= missing[A] - cnt[A];
        cnt[A] = 0;
    } else
        cnt[A] -= missing[A];
    
    // B
    if(missing[B] > cnt[B] + cnt[O]) {
        cout << "nemoguce" << endl;
        return 0;
    } else if(missing[B] > cnt[B]) {
        cnt[O] -= missing[B] - cnt[B];
        cnt[B] = 0;
    } else
        cnt[B] -= missing[B];
    
    // AB
    if(missing[AB] > cnt[A] + cnt[B] + cnt[O] + cnt[AB]) {
        cout << "nemoguce" << endl;
        return 0;
    }

    cout << "moguce" << endl;
    for(int i = 0; i < n; i++) {
        if(s[i] == "O") {
            cout << x[i] << " " << 0 << " " << 0 << " " << 0 << endl;
            continue;
        }

        if(s[i] == "A") {
            if(cnt_copy[A] >= x[i]) {
                cout << 0 << " " << x[i] << " " << 0 << " " << 0 << endl;
                cnt_copy[A] -= x[i];
            } else {
                cout << x[i] - cnt_copy[A] << " " << cnt_copy[A] << " " << 0 << " " << 0 << endl;
                cnt_copy[A] = 0;
            }
            continue;
        }

        if(s[i] == "B") {
            if(cnt_copy[B] >= x[i]) {
                cout << 0 << " " << 0 << " " << x[i] << " " << 0 << endl;
                cnt_copy[B] -= x[i];
            } else {
                cout << x[i] - cnt_copy[B] << " " << 0 << " " << cnt_copy[B] << " " << 0 << endl;
                cnt_copy[B] = 0;
            }
            continue;
        }

        if(s[i] == "AB") {
            if(cnt[AB] >= x[i]) {
                cout << 0 << " " << 0 << " " << 0 << " " << x[i] << endl;
                cnt[AB] -= x[i];
            } else if(cnt[AB] + cnt[O] >= x[i]) {
                cout << x[i] - cnt[AB] << " " << 0 << " " << 0 << " " << cnt[AB] << endl;
                cnt[O] -= x[i] - cnt[AB];
                cnt[AB] = 0;
            } else if(cnt[AB] + cnt[O] + cnt[A] >= x[i]) {
                cout << cnt[O] << " " << x[i] - cnt[O] - cnt[AB] << " " << 0 << " " << cnt[AB] << endl;
                cnt[A] -= x[i] - cnt[O] - cnt[AB];
                cnt[O] = 0;
                cnt[AB] = 0;
            } else {
                cout << cnt[O] << " " << cnt[A] << " " << x[i] - cnt[AB] - cnt[O] - cnt[A] << " " << cnt[AB] << endl;
                cnt[B] -= x[i] - cnt[O] - cnt[AB] - cnt[A];
                cnt[O] = 0;
                cnt[AB] = 0;
                cnt[A] = 0;
            }
        }
    }
    return 0;
}