#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int o, a, b, ab;
    cin >> o >> a >> b >> ab;
    string s;
    int x;

    int mat[n][4];
    bool moguce = true;

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

        cin >> s >> x;

        if(s == "O")
        {
            if(o >= x)
            {
                o = o - x;
                mat[i][0] = x;
                for(int j = 1; j <= 3; j++) mat[i][j] = 0;
            }
            else moguce = false;
        }

        if(s == "A")
        {
            if(a >= x)
            {
                a = a - x;
                mat[i][1] = x;
                mat[i][0] = 0;
                for(int j = 2; j <= 3; j ++) mat[i][j] = 0;
            }
            else if(o + a > x || o + a == x)
            {
                mat[i][1] = a;
                mat[i][0] = x - a;
                o -= x - a; a = 0;
                for(int j = 2; j <= 3; j++) mat[i][j] = 0;
            }
            else moguce = false;
        }
        if(s == "B")
        {
            if(b >= x)
            {
                b = b - x;
                mat[i][0] = 0; mat[i][1] = 0; mat[i][2] = x; mat[i][3] = 0;
            }
            else if(o + b > x || o + b == x)
            {
                mat[i][0] = x - b; mat[i][1] = 0; mat[i][2] = b; mat[i][3] = 0;
                o -= x - b; b = 0;
            }
            else moguce = false;
        }

        if(s == "AB")
        {
            if(ab > x || ab == x)
        {
                ab = ab - x;
                mat[i][3] = x;
                for(int j = 0; j <= 2; j++) mat[i][j] = 0;
            }
            else if(ab + o >= x)
            {
                mat[i][0] = x - ab; mat[i][1] = 0; mat[i][2] = 0; mat[i][3] = ab;
                o -= x - ab;
                ab = 0;
            }
            else if(ab + a >= x)
            {
                mat[i][0] = 0; mat[i][1] = x - ab; mat[i][2] = 0; mat[i][3] = ab;
                a -= x - ab;
                ab = 0;
            }
            else if(ab + b >= x)
            {
                mat[i][0] = 0; mat[i][1] = 0; mat[i][2] = x - ab; mat[i][3] = ab;
                b -= x - ab;
                ab = 0;
            }
            else moguce = false;
        }
    }

    if(moguce == true)
    {
        cout << "moguce" << endl;
        for (int i = 0; i < n; i++){
        for(int j = 0; j < 4; j++){
            cout<< mat[i][j]<< " ";
        }
        cout << endl;
        }
    }
    else {
        cout << "nemoguce";
        return 0;
    }
    return 0;
}