#include <bits/stdc++.h>
using namespace std;
int main()
{
    bool flagAB = false, moguce = true;
    int N, O, A, B, AB;
    cin >> N >> O >> A >> B >> AB;
    vector<pair<string,int>> P(N);
    vector<vector<int>> R(N, vector<int>(4));
    for (int i = 0; i < N; ++i)
    {
        R[i] = {0, 0, 0, 0};
        cin >> P[i].first;
        cin >> P[i].second;
        if (P[i].first == "O")
        {
            if (O >= P[i].second)
            {
                R[i][0] = P[i].second;
                O -= P[i].second;
            }
            else
            {
                cout << "nemoguce";
                moguce = false;
                break;
            }
        }
        else if (P[i].first == "A")
        {
            if (A > 0)
            {
                if (A >= P[i].second)
                {
                    A -= P[i].second;
                    R[i][1] = P[i].second;
                    P[i].second = 0;
                }
                else
                {
                    int dif = P[i].second - A;
                    R[i][1] = A;
                    A = 0;
                    P[i].second = dif;
                    if (O >= P[i].second)
                    {
                        O -= P[i].second;
                        R[i][0] = P[i].second;
                        P[i].second = 0;
                    }
                    else
                    {
                        cout << "nemoguce";
                        moguce = false;
                        break;
                    }
                }
            }
            else
            {
                if (O >= P[i].second)
                    {
                        O -= P[i].second;
                        R[i][0] = P[i].second;
                        P[i].second = 0;
                    }
                    else
                    {
                        cout << "nemoguce";
                        moguce = false;
                        break;
                    }
            }
        }
        else if (P[i].first == "B")
        {
            if (B > 0)
            {
                if (B >= P[i].second)
                {
                    B -= P[i].second;
                    R[i][2] = P[i].second;
                    P[i].second = 0;
                }
                else
                {
                    int dif = P[i].second - B;
                    R[i][2] = B;
                    B = 0;
                    P[i].second = dif;
                    if (O >= P[i].second)
                    {
                        O -= P[i].second;
                        R[i][0] = P[i].second;
                        P[i].second = 0;
                    }
                    else
                    {
                        cout << "nemoguce";
                        moguce = false;
                        break;
                    }
                }
            }
            else
            {
                if (O >= P[i].second)
                    {
                        O -= P[i].second;
                        R[i][0] = P[i].second;
                        P[i].second = 0;
                    }
                    else
                    {
                        cout << "nemoguce";
                        moguce = false;
                        break;
                    }
            }
        }
        else
        {
            if (AB >= P[i].second)
            {
                AB -= P[i].second;
                R[i][3] = P[i].second;
                P[i].second = 0;
            }
            else if (AB > 0)
            {
                int diff = P[i].second - AB;
                R[i][3] = AB;
                P[i].second = diff;
                AB = 0;
                flagAB = true;
            }
        }
    }
    if (flagAB)
    {
         for (int i = 0; i < N; ++i)
        {
            if (P[i].first == "AB")
            {
                if (O > 0)
                {
                    if (O >= P[i].second)
                    {
                        O -= P[i].second;
                        R[i][0] = P[i].second;
                        P[i].second = 0;
                    }
                    else
                    {
                        int diff = P[i].second - O;
                        R[i][0] = O;
                        P[i].second = diff;
                        O = 0;
                        if (B > 0)
                        {
                            if (P[i].second <= B)
                            {
                                B -= P[i].second;
                                R[i][2] = P[i].second;
                                P[i].second = 0;
                            }
                            else
                            {
                                int diff = P[i].second - B;
                                R[i][2] = B;
                                P[i].second = diff;
                                B = 0;
                                if (P[i].second <= A)
                                {
                                    A -= P[i].second;
                                    R[i][1] = P[i].second;
                                    P[i].second = 0;
                                }
                                else
                                {
                                    cout << "nemoguce";
                                    moguce = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (P[i].second <= A)
                            {
                                A -= P[i].second;
                                R[i][1] = P[i].second;
                                P[i].second = 0;
                            }
                            else
                            {
                                cout << "nemoguce";
                                moguce = false;
                                break;
                            }
                        }
                    }
                }
                else if (B > 0)
                {
                     if (P[i].second <= B)
                     {
                         B -= P[i].second;
                         R[i][2] = P[i].second;
                         P[i].second = 0;
                     }
                     else
                     {
                         int diff = P[i].second - B;
                         R[i][2] = B;
                         P[i].second -= diff;
                         B = 0;
                         if (P[i].second <= A)
                         {
                             A -= P[i].second;
                             R[i][1] = P[i].second;
                             P[i].second = 0;
                         }
                         else
                         {
                             cout << "nemoguce";
                             moguce = false;
                             break;
                         }
                     }
                }
                else if (A > 0)
                {
                    if (P[i].second <= A)
                    {
                        cout << "nemoguce";
                        moguce = false;
                        break;
                    }
                    else
                    {
                        A -= P[i].second;
                        R[i][1] = P[i].second;
                        P[i].second = 0;
                    }
                }
                else
                {
                    cout << "nemoguce";
                    moguce = false;
                    break;
                }
            }
        }
    }
    if (moguce)
    {
        cout << "moguce";
        for (int t = 0; t < N; ++t)
        {
            cout << "\n";
            for (int r = 0; r < 4; ++r)
            {
                cout << R[t][r] << " ";
            }
        }
    }
}