#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(!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;
        }
    }
}