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

const int N = 10005;

struct Node{
    int o;
    int a;
    int b;
    int ab;
};


map<string, int> prio;
pair<int, Node> res[N]; //index, val
pair<pair<string, int>, int> pat[N];

bool cmp(pair<pair<string, int>, int> x, pair<pair<string, int>, int> y){
    return prio[x.first.first] < prio[y.first.first];
}

bool cmp2(pair<int, Node> x, pair<int, Node> y){
    return x.first < y.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    prio["O"] = 0;
    prio["A"] = 1;
    prio["B"] = 2;
    prio["AB"] = 3;

    int n;
    cin >> n;
    int o, a, b, ab;
    cin >> o >> a >> b >> ab;
    for(int i = 0; i < n; ++i){
        cin >> pat[i].first.first >> pat[i].first.second;
        pat[i].second = i;
    }
    sort(pat, pat + n, cmp);

    for(int i = 0; i < n; ++i){
        res[i].first = pat[i].second; // set index
        string blood = pat[i].first.first;
        int need = pat[i].first.second;

        if(blood == "O"){
            if(o >= need){
                o -= need;
                res[i].second.o = need;
            }else{
                cout << "nemoguce\n";
                return 0;
            }
        }else if(blood == "A"){
            need = max(need - a, 0);
            a = max(a - (pat[i].first.second - need), 0);
            if(need == 0){
                res[i].second.a = pat[i].first.second;
            }else if(o >= need){
                o -= need;
                res[i].second.a = pat[i].first.second - need;
                res[i].second.o = need;
            }else{
                cout << "nemoguce\n";
                return 0;
            }
        }else if(blood == "B"){
            need = max(need - b, 0);
            b = max(b - (pat[i].first.second - need), 0);
            if(need == 0){
                res[i].second.b = pat[i].first.second;
            }else if(o >= need){
                o -= need;
                res[i].second.b = pat[i].first.second - need;
                res[i].second.o = need;
            }else{
                cout << "nemoguce\n";
                return 0;
            }
        }else{ //AB
            if(o >= need){
                o -= need;
                res[i].second.o = need;
            }else{
                need -= o;
                res[i].second.o = o;
                o = 0;
                if(a >= need){
                    a -= need;
                    res[i].second.a = need;
                }else{
                    need -= a;
                    res[i].second.a = a;
                    a = 0;
                    if(b >= need){
                        b -= need;
                        res[i].second.b = need;
                    }else{
                        need -= b;
                        res[i].second.b = b;
                        b = 0;
                        if(ab >= need){
                            ab -= need;
                            res[i].second.ab = need;
                        }else{
                            cout << "nemoguce\n";
                            return 0;
                        }
                    }
                }
            }
        }
    }

    cout << "moguce\n";
    sort(res, res + n, cmp2);
    for(int i = 0; i < n; ++i){
        cout << res[i].second.o << " " << res[i].second.a << " " << res[i].second.b << " " << res[i].second.ab << "\n";
    }
    return 0;
}