#include <bits/stdc++.h>

using namespace std;

bool moguce(int o, int a, int b, int ab, int obr, int abr, int bbr, int abbr)
{
    if(o - obr < 0)
        return false;
    o -= obr;

    if(a + o - abr < 0)
        return false;
    if(a - abr < 0)
    {
        o -= abr - a;
        a = 0;
    }
    else
        a -= abr;

    if(b + o - bbr < 0)
        return false;
    if(b - bbr < 0)
    {
        o -= bbr - b;
        b = 0;
    }
    else
        b -= bbr;


    if(a + b + ab + o - abbr < 0)
        return false;

    return true;
}
int main()
{
    int n, o, a, b, ab, obr = 0, abr = 0, bbr = 0, abbr = 0;
    cin >> n;
    cin >> o >> a >> b >> ab;
    vector <int> pac;
    vector <string> pacg;

    for(int i = 0; i < n; i++)
    {
        string p, pg; int kol = 0;
        cin >> p;
        cin >> kol;

        if(p[0] == 'O')
            pg = "O";
        else if(p[0] == 'A' && p[1] == 'B')
            pg = "AB";
        else if(p[0] == 'B')
            pg = "B";
        else
            pg = "A";

        //dodaje info o pacijentu na vektor
        if(pg == "O")
        {
            pacg.push_back(pg);
            pac.push_back(kol);
            obr += kol;
        }
        else if(pg == "A")
        {
            pacg.push_back(pg);
            pac.push_back(kol);
            abr += kol;
        }
        else if(pg == "B")
        {
            pacg.push_back(pg);
            pac.push_back(kol);
            bbr += kol;
        }
        else
        {
            pacg.push_back(pg);
            pac.push_back(kol);
            abbr += kol;
        }
    }


    if(moguce(o, a, b, ab, obr, abr, bbr, abbr))
    {
        cout << "moguce" << endl;
        for(int i = 0; i < n; i++)
        {
            if(pacg[i] == "O")
            {
                cout << pac[i] << " 0 0 0" << endl;
                o -= pac[i];
            }
            else if(pacg[i] == "A")
            {
                if(a < pac[i])
                {
                    cout << pac[i] - a << " " << a << " 0 0" << endl;
                    o -= pac[i]- a;
                    a = 0;
                }
                else
                {
                    cout << "0 " << pac[i] << " 0 0" << endl;
                    a -= pac[i];
                }
            }
            else if(pacg[i] == "B")
            {
                if(b < pac[i])
                {
                    cout << pac[i] - b << " 0 " << b << " 0" << endl;
                    o -= pac[i] - b;
                    b = 0;
                }
                else
                {
                    cout << "0 0 " << pac[i] << " 0" << endl;
                    b -= pac[i];
                }
            }
            else if(pacg[i] == "AB")
            {
                if(ab >= pac[i])
                {
                    cout << "0 0 0 " << pac[i] << endl;
                    ab -= pac[i];
                }
                else if(ab + o >= pac[i])
                {
                    cout << pac[i] - ab << " 0 0 " << ab << endl;
                    o -= pac[i] - ab;
                    ab = 0;
                }
                else if(ab + o + a >= pac[i])
                {
                    cout << o << " " << pac[i] - ab - o << " 0 " << ab << endl;
                    a -= pac[i] - ab - o;
                    ab = 0;
                    o = 0;
                }
                else
                {
                    cout << o << " " << a << " " << pac[i] - ab - o - a << " 0 " << ab;
                    b -= pac[i] - ab - o - a;
                    ab = 0;
                    o = 0;
                    a = 0;
                }

            }
        }
    }
    else
        cout << "nemoguce";


    return 0;
}