#include <bits/stdc++.h>

using namespace std;

#define maxN 1001

vector<string> krv;
vector<int> kolicina;
vector<int> izrodi;
vector<int> index_izroda;

int mat[maxN][4];
int velko = 0;

int main()
{
    memset(mat, 0, sizeof(mat));

    int n;
    cin >> n;

    int o, a, b, ab;

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

    for(int i = 0; i < n; i++)
    {
        string s;
        int x;

        cin >> s;
        krv.push_back(s);

        cin >> x;
        kolicina.push_back(x);
    }

    for(int i = 0; i < n; i++)
    {
        if(krv[i] == "O")
        {
            if(o >= kolicina[i])
            {
                o -= kolicina[i];
                mat[i][0] += kolicina[i];
            }
            else
            {
                cout << "nemoguce" << '\n';
                return 0;
            }
        }
        else if(krv[i] == "A")
        {
            if(a >= kolicina[i])
            {
                a -= kolicina[i];
                mat[i][1] += kolicina[i];
            }
            else
            {
                kolicina[i] -= a;
                mat[i][1] = a;
                a = 0;

                if(o >= kolicina[i])
                {
                    o -= kolicina[i];
                    mat[i][0] += kolicina[i];
                }
                else
                {
                    cout << "nemoguce" << '\n';
                    return 0;
                }
            }
        }
        else if(krv[i] == "B")
        {
            if(b >= kolicina[i])
            {
                b -= kolicina[i];
                mat[i][2] += kolicina[i];
            }
            else
            {
                mat[i][2] += b;
                kolicina[i] -= b;
                b = 0;

                if(o >= kolicina[i])
                {
                    o -= kolicina[i];
                    mat[i][0] += kolicina[i];
                }
                else
                {
                    cout << "nemoguce" << '\n';
                    return 0;
                }
            }
        }
        else
        {
            if(ab >= kolicina[i])
            {
                ab -= kolicina[i];
                mat[i][3] += kolicina[i];
            }
            else
            {
                kolicina[i] -= ab;
                mat[i][3] += ab;
                ab = 0;

                izrodi.push_back(kolicina[i]);
                index_izroda.push_back(i);
                velko++;
            }
        }
    }

    for(int i = 0; i < velko; i++)
    {
        if(b >= izrodi[i])
        {
            b -= izrodi[i];
            mat[index_izroda[i]][2] += izrodi[i];
        }
        else
        {
            izrodi[i] -= b;
            mat[index_izroda[i]][2] += b;
            b = 0;

            if(a >= izrodi[i])
            {
                a -= izrodi[i];
                mat[index_izroda[i]][1] += izrodi[i];
            }
            else
            {
                izrodi[i] -= a;
                mat[index_izroda[i]][1] += a;
                a = 0;

                if(o >= izrodi[i])
                {
                    o -= izrodi[i];
                    mat[index_izroda[i]][0] += izrodi[i];
                }
                else
                {
                    cout << "nemoguce" << '\n';
                    return 0;
                }
            }
        }
    }

    cout << "moguce" << '\n';

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            cout << mat[i][j] << " ";
        }
        cout << '\n';
    }


    return 0;
}