#include <iostream>

using namespace std;

int main()
{
    int n, o, a, b, ab;
    cin >> n;
    cin >> o >> a >> b >> ab;
    string *s = new string[n];
    int *p = new int[n];
    int *no = new int[n];
    int *na = new int[n];
    int *nb = new int[n];
    int *nab = new int[n];
    int po = 0;
    int pa = 0;
    int pb = 0;
    int pab = 0;
    for(int i = 0; i < n; i++){
        cin >> s[i] >> p[i];
        if(s[i] == "O") po += p[i];
        else if(s[i] == "A") pa += p[i];
        else if(s[i] == "B") pb += p[i];
        else pab += p[i];
        no[i] = 0;
        na[i] = 0;
        nb[i] = 0;
        nab[i] = 0;
    }
    if(po > o) cout << "nemoguce";
    else if(pa + po > a + o) cout << "nemoguce";
    else if(pb + po > b + o) cout << "nemoguce";
    else if(pa + pb + po > a + b + o) cout << "nemoguce";
    else if(pab + pa + pb + po > ab + a + b + o) cout << "nemoguce";
    else{
        int vo = o - po;
        int va = a - pa;
        int vb = b - pb;
        cout << "moguce" << endl;
        for(int i = 0; i < n; i++){
            if(s[i] == "O") no[i] += p[i];
            else if(s[i] == "A"){
                if(a >= p[i]){
                    a -= p[i];
                    na[i] += p[i];
                }
                else{
                    na[i] += a;
                    p[i] -= a;
                    a = 0;
                    vo -= p[i];
                    no[i] += p[i];
                }
            }

            else if(s[i] == "B"){
                if(b >= p[i]){
                    b -= p[i];
                    nb[i] += p[i];
                }
                else{
                    nb[i] += b;
                    p[i] -= b;
                    b = 0;
                    vo -= p[i];
                    no[i] += p[i];
                }
            }

            else{
                if(ab >= p[i]){
                    a -= p[i];
                    nab[i] += p[i];
                }
                else{
                    nab[i] += ab;
                    p[i] -= ab;
                    ab = 0;
                    if(va >= p[i]){
                        va -= p[i];
                        na[i] += p[i];
                    }
                    else{
                        if(va > 0){
                            na[i] += va;
                            p[i] -= va;
                            va = 0;
                        }
                        if(vb >= p[i]){
                            vb -= p[i];
                            nb[i] += p[i];
                        }
                        else{
                            if(vb > 0){
                                nb[i] += vb;
                                p[i] -= vb;
                                vb = 0;
                            }
                            vo -= p[i];
                            no[i] += p[i];
                        }
                    }
                }
            }
            cout << no[i] << " " << na[i] << " " << nb[i] << " " << nab[i] << endl;
        }
    }
    return 0;
}