#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n, a, b, o, ab;
    bool da_end = true;
    long long ab_counter = 0;

    cin >> n >> o >> a >> b >> ab;

    string grupa[1000];
    int jedinica[1000], reso[1000], resa[1000], resb[1000], resab[1000];

    for (int i = 0; i < n; i++){
        cin >> grupa[i] >> jedinica[i];
        if (grupa[i] == "O"){
            reso[i] = jedinica[i];
            o = o -jedinica[i];
            resa[i] = 0;
            resb[i] = 0;
            resab[i] = 0;
        }

        else if (grupa[i] == "A"){
            if (jedinica[i] > a){
                reso[i] = jedinica[i] - a;
                o = o - jedinica[i] + a;
                resa[i] = a;
                a = 0;
                resb[i] = 0;
                resab[i] = 0;
            }
            else {
                reso[i] = 0;
                resa[i] = jedinica[i];
                a = a - jedinica[i];
                resb[i] = 0;
                resab[i] = 0;
            }
        }

        else if (grupa[i] == "B"){
            if (jedinica[i] > b){
                reso[i] = jedinica[i] - b;
                o = o - jedinica[i] + b;
                resa[i] = 0;
                resb[i] = b;
                b = 0;
                resab[i] = 0;
            }
            else {
                reso[i] = 0;
                resa[i] = 0;
                resb[i] = jedinica[i];
                b = b - jedinica[i];
                resab[i] = 0;
            }
        }
        else {
            ab_counter = ab_counter + jedinica[i];
        }

    }

    if (o < 0 || a < 0 || b < 0 || ab_counter > o + a + b + ab){
        cout << "nemoguce";
    }
    else {
        cout << "moguce" << endl;
        for (int i = 0; i < n; i++){
            if (grupa[i] == "AB"){
                if (jedinica[i] > o){
                    reso[i] = o;
                    o = 0;

                    if (jedinica[i] > a + reso[i]){
                        resa[i] = a;
                        a = 0;
                        if (jedinica[i] > b + reso[i] + resa[i]){
                            resb[i] = b;
                            b = 0;
                            resab[i] = jedinica[i] - reso[i] - resa[i] - resb[i];
                            ab = ab - jedinica[i] + reso[i] + resa[i] + resb[i];
                        }
                        else {
                            resb[i] = jedinica[i] - reso[i] - resa[i];
                            b = b - jedinica[i] + reso[i] + resa[i];
                        }
                    }
                    else {
                        resa[i] = jedinica[i] - reso[i];
                        a = a - jedinica[i] + reso[i];
                        resb[i] = 0;
                        resab[i] = 0;
                    }
                }
                else {
                    reso[i] = jedinica[i];
                    o = o - jedinica[i];
                    resa[i] = 0;
                    resb[i] = 0;
                    resab[i] = 0;
                }
            }
        }
        for (int i = 0; i < n; i++){
        cout << reso[i] << " " << resa[i] << " " << resb[i] << " " << resab[i] << endl;
        }
    }

}