#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    long long N,O,A,B,AB;
    cin >> N;
    cin >> O >> A >> B >> AB;
    stringstream res[N];
    vector<pair<long long,long long>> ABp;
    long long ABuk = 0;
    for(int i = 0;i<N;i++)
    {
        string c;
        long long j;
        cin >> c >> j;
        if(c == "O")
        {
            res[i] << j << " 0 0 0";
            O-=j;
        }
        else if(c == "A")
        {
            if(A>=j)
            {
                res[i] << "0 " <<  j << " 0 0";
                A-=j;
            }
            else
            {
                res[i] << j-A << " " << A << " 0 0";
                j -= A;
                O -= j;
                A = 0;
            }
        }
        else if(c == "B")
        {
            if(B>=j)
            {
                res[i] << "0 0 " << j << " 0";
                B-=j;
            }
            else
            {
                res[i] << j-B << " 0 " << B << " 0";
                j -= B;
                O -= j;
                B = 0;
            }
        }
        else
        {
            ABp.push_back(make_pair(i,j));
            ABuk += j;
        }
        if(A < 0 || B < 0 || O < 0)
        {
            cout << "nemoguce" << endl;
            return 0;
        }

        //cout << O << " " << A << " " << B << " " << AB << endl;
        //cout << res[i].str() << endl << endl;
    }
    if(ABuk > A+B+AB+O)
    {
        cout << "nemoguce" << endl;
        return 0;
    }

    for(int i = 0;i<ABp.size();i++)
    {
        long long a = 0,b = 0,o = 0,ab = 0;
        if(AB >= ABp[i].second)
        {
            ab = ABp[i].second;
            AB -= ab;
        }
        else
        {
            ab = AB;
            AB = 0;
            ABp[i].second -= ab;
            if(A >= ABp[i].second)
            {
                a = ABp[i].second;
                A -= a;
            }
            else
            {
                a = A;
                A = 0;
                ABp[i].second -= a;
                if(B >= ABp[i].second)
                {
                    b = ABp[i].second;
                    B-= b;
                }
                else
                {
                    b = B;
                    B = 0;
                    ABp[i].second -= b;

                    o = ABp[i].second;
                    O -= o;
                }
            }
        }

        res[ABp[i].first] << o << " " << a << " " << b << " " << ab;

        if(O < 0)
        {
            cout << "nemoguce" << endl;
            return 0;
        }
    }


    cout << "moguce" << endl;
    for(int i = 0;i<N;i++)
    {
        cout << res[i].str() << endl;
    }

    return 0;
}