#include<bits/stdc++.h>

using namespace std;


struct Pacijent{
    string grupa;
    int brJedinica;
    int x[4];
};

void rasporedi(Pacijent *k, int *r, int *o, bool *p){
    int index;
    if((*k).grupa == "A") index = 1;
    else index = 2;

    if((*k).brJedinica <= *r){
        *r -= (*k).brJedinica;
        (*k).x[index] = (*k).brJedinica;
    }
    else{
        if((*k).brJedinica <= (*r+*o)){

            (*k).x[index] = *r;
            (*k).x[0] = (*k).brJedinica - *r;
            *o -= ((*k).brJedinica - *r);
            *r = 0;
        }
        else{
            *p = false;
        }


    }


}
int main()
{
    ios :: sync_with_stdio(0);
    cin.tie(0);
    vector<Pacijent> v;
    bool moguce = true;
    int n, o, a, b, ab, br;
    cin >> n;
    cin >> o >> a >> b >> ab;

    Pacijent k[n];
    for (int i = 0; i < n; i++){
        cin >> k[i].grupa >> k[i].brJedinica;
        for (int j = 0; j < 4; j++){
            k[i].x[j] = 0;
        }
        if(k[i].grupa == "O" && k[i].brJedinica <= o){
            o -= k[i].brJedinica;
            k[i].x[0] = k[i].brJedinica;
        }
        else if(k[i].grupa == "O")
            moguce = false;
    }
    if(moguce){
       for (int i = 0; i < n; i++){
           if(k[i].grupa == "A")
                rasporedi(&k[i], &a, &o, &moguce);
           else if(k[i].grupa == "B")
                rasporedi(&k[i], &b, &o, &moguce);
           else if (k[i].grupa == "AB")
                v.push_back(k[i]);
           if(!moguce)
                break;
       }

       if(moguce){
            for (int i = 0; i < v.size(); i++){
                br = v[i].brJedinica;
                if(br <= (a+b+ab+o)){
                    if(br <= ab){
                        v[i].x[3] = br;
                        ab -= br;
                        br = 0;
                    }
                    else{

                        v[i].x[3] = ab;
                        br -= ab;
                        ab = 0;

                    }
                    if(br <= a){
                        v[i].x[1] = br;
                        a -= br;
                        br = 0;
                    }
                    else{
                        v[i].x[1] = a;
                        br -= a;
                        a = 0;

                    }
                    if(br <= b){
                        v[i].x[2] = br;
                        b -= br;
                        br = 0;
                    }
                    else{
                        v[i].x[2] = b;
                        br -= b;
                        b = 0;
                    }
                    if(br <= o){
                        v[i].x[0] = br;
                        o -= br;
                        br = 0;
                    }
                    else{
                        v[i].x[0] = o;
                        br -= o;
                        o = 0;
                    }
                }
                else
                    moguce = false;
            }
       }
    }
    br = 0;
    if(moguce){
        cout << "moguce\n";
        for (int i = 0; i < n; i++){
            if(k[i].grupa == "AB"){
                for (int j = 0; j < 4; j++){
                    cout << v[br].x[j] << " ";
                }
                cout << "\n";
                br++;
            }
            else{
                for (int j = 0; j < 4; j++){
                    cout << k[i].x[j] << " ";
                }
                cout << "\n";
            }

        }
    }
    else{
        cout << "nemoguce\n";
    }


    return 0;
}