#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main()
{
    int possible = 1;
    int n;
    cin >> n;
    int o, a, b, ab;

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

    vector<string> gr;
    int *kolicina = (int*)calloc(n, sizeof(int));
    int *rez = (int*)calloc(n*4, sizeof(int));
    for (int i = 0; i < n*4; i++)
    {
        rez[i] = 0;
    }
    for (int i = 0; i < n; i++)
    {
        string pom;
        cin >> pom >> kolicina[i];
        gr.push_back(pom);
    }

    int oc = o, ac = a, bc = b, abc = ab;

    for (int i = 0; i < n; i++)
    {
        if (gr[i] == "O")
        {
            if (kolicina[i] <= oc)
            {
                oc -= kolicina[i];
                rez[i*4] = kolicina[i];
            }
            else
            {
                possible = 0;
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (gr[i] == "A")
        {
            if (kolicina[i] <= ac)
            {
                ac -= kolicina[i];
                rez[i*4+1] = kolicina[i];
            }
            else if(kolicina[i] <= ac+oc)
            {
                int pom = kolicina[i] - ac;
                ac = 0;
                rez[i*4+1] = kolicina[i] - pom;
                oc -= pom;
                rez[i*4] = pom;
            }
            else
            {
                possible = 0;
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (gr[i] == "B")
        {
            if (kolicina[i] <= bc)
            {
                bc -= kolicina[i];
                rez[i*4+2] = kolicina[i];
            }
            else if(kolicina[i] <= bc+oc)
            {
                int pom = kolicina[i] - bc;
                rez[i*4+2] = kolicina[i] - pom;
                bc = 0;
                oc -= pom;
                rez[i*4] = pom;
            }
            else
            {
                possible = 0;
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (gr[i] == "AB")
        {
            if (kolicina[i] <= ac+bc+oc+abc)
            {
                int pom = kolicina[i];
                while (pom > 0)
                {
                    if (oc >= pom)
                    {
                        oc -= pom;
                        rez[i*4] = pom;
                        break;
                    }
                    else
                    {
                        int pom2 = oc;
                        oc = 0;
                        pom -= pom2;
                        rez[i*4] = pom2;
                    }

                    if (ac >= pom)
                    {
                        ac -= pom;
                        rez[i*4+1] = pom;
                        break;
                    }
                    else
                    {
                        int pom2 = ac;
                        ac = 0;
                        pom -= pom2;
                        rez[i*4+1] = pom2;
                    }

                    if (bc >= pom)
                    {
                        bc -= pom;
                        rez[i*4+2] = pom;
                        break;
                    }
                    else
                    {
                        int pom2 = bc;
                        bc = 0;
                        pom -= pom2;
                        rez[i*4+2] = pom2;
                    }

                    if (abc >= pom)
                    {
                        abc -= pom;
                        rez[i*4+3] = pom;
                        break;
                    }
                    else
                    {
                        int pom2 = abc;
                        abc = 0;
                        pom -= abc;
                        rez[i*4+3] = pom2;
                    }
                }
            }
            else
            {
                possible = 0;
            }
        }
    }

    if (possible == 0)
    {
        cout << "nemoguce";
    }
    else
    {
        cout << "moguce" << endl;
        for (int i = 0; i < n*4; i += 4)
        {
            cout << rez[i]<<" " << rez[i+1]<<" " << rez[i+2]<<" " << rez[i+3] << endl;
        }
    }
    return 0;
}