#include<bits/stdc++.h>

using namespace std;

struct x
{
    string type;
    unsigned long long tempNum = 0;
    unsigned long long numO = 0;
    unsigned long long numA = 0;
    unsigned long long numB = 0;
    unsigned long long numAB = 0;
};

int main()
{
    unsigned long long int n;
    unsigned long long int loadO, loadA, loadB, loadAB;
    bool mog = true;
    cin >> n;
    cin >> loadO >> loadA >> loadB >> loadAB;
    x a[n];
    for(unsigned long long int i=0;i<n;++i)
    {
        cin >> a[i].type >> a[i].tempNum;
    }
    for(unsigned long long int i=0;i<n;++i)
    {
        if(a[i].type == "O")
        {
            if(a[i].tempNum > loadO)
            {
                mog = false;
                break;
            }
            if(loadO >= a[i].tempNum)
            {
                a[i].numO += a[i].tempNum;
                loadO -= a[i].tempNum;
                a[i].tempNum = 0;
            }
            else
            {
                if(a[i].tempNum > 0)
                    mog = false;
            }
        }
        else if(a[i].type == "A")
        {
            if(a[i].tempNum > loadA + loadO)
            {
                mog = false;
                break;
            }
            if(loadA >= a[i].tempNum)
            {
                a[i].numA += a[i].tempNum;
                loadA -= a[i].tempNum;
                a[i].tempNum = 0;
            }
            else
            {
                a[i].numA += loadA;
                a[i].tempNum -= loadA;
                loadA = 0;
                loadO -= a[i].tempNum;
                a[i].numO += a[i].tempNum;
                a[i].tempNum -= loadO;

                if(a[i].tempNum > 0)
                    mog = false;
            }
        }
        else if(a[i].type == "B")
        {
            if(a[i].tempNum > loadB + loadO)
            {
                mog = false;
                break;
            }
            if(loadB >= a[i].tempNum)
            {
                a[i].numB += a[i].tempNum;
                loadB -= a[i].tempNum;
                a[i].tempNum = 0;
            }
            else
            {
                a[i].numB += loadB;
                a[i].tempNum -= loadB;
                loadB = 0;

                loadO -= a[i].tempNum;
                a[i].numO += a[i].tempNum;

                if(a[i].tempNum > 0)
                    mog = false;
            }
        }
        else
        {
            if(a[i].tempNum > loadAB + loadA + loadB + loadO)
            {
                mog = false;
                break;
            }
            if(loadAB >= a[i].tempNum)
            {
                a[i].numAB += a[i].tempNum;
                loadAB -= a[i].tempNum;
                a[i].tempNum = 0;
            }
            else
            {
                a[i].numAB += loadAB;
                a[i].tempNum -= loadAB;
                loadAB = 0;

                if(loadA >= a[i].tempNum)
                {
                    a[i].numA += a[i].tempNum;
                    loadA -= a[i].tempNum;
                    a[i].tempNum = 0;
                }
                else
                {
                    a[i].numA += loadA;
                    a[i].tempNum -= loadA;
                    loadA = 0;

                    if(loadB >= a[i].tempNum)
                    {
                        a[i].numB += a[i].tempNum;
                        loadB -= a[i].tempNum;
                        a[i].tempNum = 0;
                    }
                    else
                    {
                        a[i].numB += loadB;
                        a[i].tempNum -= loadB;
                        loadB = 0;

                        if(loadO >= a[i].tempNum)
                        {
                            a[i].numO += a[i].tempNum;
                            loadO -= a[i].tempNum;
                            a[i].tempNum = 0;
                        }
                        else
                        {
                            mog = false;
                        }
                    }
                }
            }
        }
        if(loadO<0 || loadA<0  || loadB<0  || loadAB<0 )
            mog = false;
        else mog = true;
    }
    if(mog == false)
    {
        cout << "nemoguce" << endl;
        return 0;
    }
    else
    {
        cout << "moguce" << endl;
        for(unsigned long long int i=0;i<n;++i)
        {
            cout << a[i].numO << " " << a[i].numA << " " << a[i].numB << " " << a[i].numAB << endl;
        }
    }
    return 0;
}