#include <bits/stdc++.h>
#define sp " "
#define en '\n'

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    int N;
    cin >> N;
    int O, A, B, AB;
    cin >> O >> A >> B >> AB;
    vector <string> s (N);
    vector <int> a (N);
    for (int i = 0; i < N; i++)
        cin >> s[i] >> a[i];
    int ans [N] [4];
    bool moze = true;
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < N; j++)
        {
            int O1 = 0, A1 = 0, B1 = 0, AB1 = 0;
            if (i == 0 && s[j] == "O")
            {
                if (a[j] > O)
                    moze = false;
                else
                {
                    O1 = a[j];
                    O -= O1;
                }
                ans[j][0] = O1, ans[j][1] = A1, ans[j][2] = B1, ans[j][3] = AB1;
            }
            else if (i == 1 && s[j] == "A")
            {
                if (a[j] > O + A)
                    moze = false;
                else
                {
                    A1 = a[j];
                    A -= A1;
                    if (A < 0)
                    {
                        A1 += A;
                        A = 0;
                        O1 = a[j] - A1;
                        O -= O1;
                    }
                }
                ans[j][0] = O1, ans[j][1] = A1, ans[j][2] = B1, ans[j][3] = AB1;
            }
            else if (i == 2 && s[j] == "B")
            {
                if (a[j] > O + B)
                    moze = false;
                else
                {
                    B1 = a[j];
                    B -= B1;
                    if (B < 0)
                    {
                        B1 += B;
                        B = 0;
                        O1 = a[j] - B1;
                        O -= O1;
                    }
                }
                ans[j][0] = O1, ans[j][1] = A1, ans[j][2] = B1, ans[j][3] = AB1;
            }
            else if (i == 3 && s[j] == "AB")
            {
                if (a[j] > O + A + B + AB)
                    moze = false;
                else
                {
                    AB1 = a[j];
                    AB -= AB1;
                    if (AB < 0)
                    {
                        AB1 += AB;
                        AB = 0;
                        B1 = a[j] - AB1;
                        B -= B1;
                        if (B < 0)
                        {
                            B1 += B;
                            B = 0;
                            A1 = a[j] - AB1 - B1;
                            A -= A1;
                            if (A < 0)
                            {
                                A1 += A;
                                A = 0;
                                O1 = a[j] - AB1 - B1 - A1;
                                O -= O1;
                            }
                        }
                    }
                }
                ans[j][0] = O1, ans[j][1] = A1, ans[j][2] = B1, ans[j][3] = AB1;
            }
        }
    }
    if (moze)
    {
        cout << "moguce" << en;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < 4; j++)
                cout << ans[i][j] << sp;
            cout << en;
        }
    }
    else
        cout << "nemoguce";
    return 0;
}