#include <iostream>
#include <string>
using namespace std;


struct pac
{
    string kg;
    int uk;
    int brO;
    int brA;
    int brB;
    int brAB;
};

int main()
{
    pac arr[10000];
    int n;
    int jed[4];
    string pomarr[10000];
    bool kraj = 0;

    cin >> n;

    for (int i = 0; i < 4; i++) {
        cin >> jed[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> arr[i].kg >> arr[i].uk;
    }
    for (int i = 0; i < n; i++) {
        arr[i].brO = 0;
        arr[i].brA = 0;
        arr[i].brB = 0;
        arr[i].brAB = 0;

        pomarr[i] = arr[i].kg;
    }

    int po = 0, pa = 0, pb = n - 1, pab = n - 1;
    int temp = 0;
    pac pom;

    while (pa <= pb)
    {
        if (arr[pa].kg == "O") {
            pom = arr[po];
            arr[po] = arr[pa];
            arr[pa] = pom;
            po++;
            pa++;

            //cout << "usao u o " << endl;
        }
        else if (arr[pa].kg == "A") {
            pa++;

            //cout << "usao u a " << endl;
        }
        else if (arr[pa].kg == "B") {
            pom = arr[pb];
            arr[pb] = arr[pa];
            arr[pa] = pom;
            pb--;
           // cout << "usao u b " << endl;

        }
        else if (arr[pa].kg == "AB") {
            pom = arr[pa];
            arr[pa] = arr[pb];
            arr[pb] = pom;

            pom = arr[pb];
            arr[pb] = arr[pab];
            arr[pab] = pom;
            pb--;
            pab--;
        }

    }
    po = 0;
    pa = 0;
    pb = 0;
    pab = 0;
    for (int i = 0; i < n; i++)
    {
        if ((pa == 0) && (arr[i].kg == "A")) {
            pa = i;
        }
        if ((pb == 0) && (arr[i].kg == "B")) {
            pb = i;
        }
        if ((pab == 0) && (arr[i].kg == "AB")) {
            pab = i;
        }
        if ((po == 0) && (arr[i].kg == "O")) {
            po = i;
        }

    }
    for (int i = 0; i < n; i++) {
        if (arr[i].kg == "O") {
            while (arr[i].uk > 0) {
                if (jed[0] > 0) {
                    jed[0]--;
                    arr[i].brO++;
                    arr[i].uk--;
                }
                else {
                    cout << "nemoguce" << endl;
                    kraj = 1;
                    break;
                }
            } 
        }
        if (arr[i].kg == "A") {
            while (arr[i].uk > 0) {
                if (jed[1] > 0) {
                    jed[1]--;
                    arr[i].brA++;
                    arr[i].uk--;
                }
                else {
                    if (jed[0] > 0) {
                        jed[0]--;
                        arr[i].brO++;
                        arr[i].uk--;
                    }
                    else {
                        cout << "nemoguce" << endl;
                        kraj = 1;
                        break;
                    }

                }
            }
            

        }
        if (arr[i].kg == "B") {
            while (arr[i].uk > 0) {
                if (jed[2] > 0) {
                    jed[2]--;
                    arr[i].brB++;
                    arr[i].uk--;
                }
                else {
                    if (jed[0] > 0) {
                        jed[0]--;
                        arr[i].brO++;
                        arr[i].uk--;
                    }
                    else {
                        cout << "nemoguce" << endl;
                        kraj = 1;
                        break;
                    }

                }
            }
            

        }
        if (arr[i].kg == "AB") {
            while (arr[i].uk > 0) {
                if (jed[2] > 0) {
                    jed[2]--;
                    arr[i].brB++;
                    arr[i].uk--;
                }
                else {
                    if (jed[0] > 0) {
                        jed[0]--;
                        arr[i].brO++;
                        arr[i].uk--;
                    }
                    else {
                        if (jed[1] > 0) {
                            jed[1]--;
                            arr[i].brA++;
                            arr[i].uk--;
                        }
                        else if (jed[3] > 0) {
                            jed[1]--;
                            arr[i].brAB++;
                            arr[i].uk--;
                        }
                        else {
                            cout << "nemoguce" << endl;
                            kraj = 1;
                            break;
                        }
                        
                    }

                }
            }

        }
    }
    if (kraj == 0) {
        cout << "moguce" << endl;
        for (int i = 0; i < n; i++) {
            if (pomarr[i] == "O") {
                cout << arr[po].brO << " " << arr[po].brA << " " << arr[po].brB << " " << arr[po].brAB <<endl;
                //cout << po << endl;
                po++;
            }
            if (pomarr[i] == "A") {
                cout << arr[pa].brO << " " << arr[pa].brA << " " << arr[pa].brB << " " << arr[pa].brAB << endl;
                //cout << pa << endl;
                pa++;
            }
            if (pomarr[i] == "B") {
                cout << arr[pb].brO << " " << arr[pb].brA << " " << arr[pb].brB << " " << arr[pb].brAB << endl;
                //cout << pb<< endl;
                pb++;
            }
            if (pomarr[i] == "AB") {
                cout << arr[pab].brO << " " << arr[pab].brA << " " << arr[pab].brB << " " << arr[pab].brAB << endl;
                //cout << pab << endl;
                pab++;
            }
        }
    }
    

    return 0;
}