#include <bits/stdc++.h>

using namespace std;

int resenje[4][10000];

int main()
{
    int n; cin>>n;
    int nO, nA, nB, nAB;
    cin>>nO>>nA>>nB>>nAB;

    string s2;
    int s2L, nT;
    bool moguce = true;

    int ukupno;

    for(int i = 0; i < n; i++)
    {
        cin>>s2>>nT;
        s2L = s2.length();

        ukupno = nO+nA+nB+nAB;

        if(s2L == 1)
        {
            if(s2[0] == 'A')
            {
                if(nT > nA && nT <= nA + nO)
                {
                    nO -= (nT-nA);
                    resenje[i][0] = nT-nA;
                    resenje[i][1] = nA;
                    nA = 0;
                }
                else if(nT <= nA)
                {
                    resenje[i][1] = nT;
                    nA-=nT;
                }
                else {moguce = false; break;}
            }
            else if(s2[0] == 'B')
            {
                if(nT > nB && nT <= nB + nO)
                {
                    nO -= (nT-nB);
                    nB = 0;
                    resenje[i][0] = nT-nB;
                    resenje[i][2] = nB;
                }
                else if(nT <= nB)
                {
                    resenje[i][2] = nT;
                    nB-=nT;
                }
                else {moguce = false; break;}
            }
            else if(s2[0] == 'O')
            {
                if(nO >= nT)
                {
                    resenje[i][0] = nT;
                    nO-=nT;
                }
                else {moguce = false; break;}
            }
        }
        else
        {
            if(nT > ukupno) {moguce = false; break;}
            if(nT <= nAB)
            {
                nAB-=nT;
                resenje[i][3] = nT;
            }
            else if(nT <= nAB + nA)
            {
                nA -= (nT-nAB);
                resenje[i][1] = nT-nAB;
                resenje[i][3] = nAB;
                nAB = 0;
            }
            else if(nT <= nAB + nB)
            {
                nB -= (nT-nAB);
                resenje[i][2] = nT-nAB;
                resenje[i][3] = nAB;
                nAB = 0;
            }
            else if(nT <= nAB + nO)
            {
                nO -= (nT-nAB);;
                resenje[i][0] = nT-nAB;
                resenje[i][3] = nAB;
                nAB = 0;
            }
            else if(nT <= nAB + nA + nB)
            {
                nB -= (nT-nAB-nA);
                resenje[i][1] = nA;
                resenje[i][2] = nT-nAB-nA;
                resenje[i][3] = nAB;
                nAB = 0;
                nA = 0;
            }
            else if(nT <= nAB + nA + nO)
            {
                nO -= (nT-nAB-nA);
                resenje[i][1] = nA;
                resenje[i][0] = nT-nAB-nA;
                resenje[i][3] = nAB;
                nAB = 0;
                nA = 0;
            }
            else if(nT <= nAB + nB + nO)
            {
                nO -= (nT-nAB-nB);
                resenje[i][2] = nB;
                resenje[i][0] = nT-nAB-nB;
                resenje[i][3] = nAB;
                nAB = 0;
                nB = 0;
            }
        }
    }

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