#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int N,ZO,ZA,ZB,ZAB,i,l;
    cin >> N;
    string kg[N];
    int j[N],O[N],A[N],B[N],AB[N], indeks[N];
    bool moguce=true;

    cin >> ZO >> ZA >> ZB >> ZAB;
    for(i=0; i<N; i++)
    {
        cin >> kg[i] >> j[i];
        indeks[i]=i;
    }
    l=N-1;
    while(kg[l]=="AB")
        l--;
    int x=l;
    int y=l;
    for(i=0; i<x+1; i++)
    {
        
        if(kg[i]=="AB")
        {
            swap(kg[i],kg[l]);
            swap(j[i],j[l]);
            swap(indeks[i],indeks[l]);
            l--;
            x--;
        }
    }

    for(i=0; i<N; i++)
    {
        O[i]=0; A[i]=0; B[i]=0; AB[i]=0;

        if(kg[i]=="O")
        {
            if(ZO>=j[i])
            {
                ZO-=j[i];
                O[i]=j[i];
            }
            else
            {
                moguce=false;
                break;
            }          
        }
        else if(kg[i]=="A")
        {
            if(ZA>=j[i])
            {
                ZA-=j[i];
                A[i]=j[i];
            }
            else if(ZA+ZO>=j[i])
            {
                A[i]=ZA;
                ZO=ZO+ZA-j[i];
                O[i]=j[i]-ZA;
                ZA=0;
            }
            else
            {
                moguce=false;
                break;
            }
        }
        else if(kg[i]=="B")
        {
            if(ZB>=j[i])
            {
                ZB-=j[i];
                B[i]=j[i];
            }
            else if(ZB+ZO>=j[i])
            {
                B[i]=ZB;
                ZO=ZO+ZB-j[i];
                O[i]=j[i]-ZB;
                ZB=0;
            }
            else
            {
                moguce=false;
                break;
            }
        }
        else
        {
            if(ZAB>=j[i])
            {
                AB[i]=j[i];
                ZAB-=j[i];
            }
            else if(ZAB+ZA>=j[i])
            {
                AB[i]=ZAB;
                A[i]=j[i]-ZAB;
                ZAB=0;
                ZA-=A[i];
            }
            else if(ZAB+ZA+ZB>=j[i])
            {
                AB[i]=ZAB;
                A[i]=ZA;
                B[i]=j[i]-(ZAB+ZA);
                ZAB=0;
                ZA=0;
                ZB-=B[i];
            }
            else if(ZAB+ZA+ZB+ZO>=j[i])
            {
                AB[i]=ZAB;
                A[i]=ZA;
                B[i]=ZB;
                O[i]=j[i]-(ZA+ZB+ZAB);
                ZAB=0;
                ZA=0;
                ZB=0;
                ZO-=O[i];
            }
            else
            {
                moguce=false;
                break;
            }
        }
    }
    if(moguce)
    {
        for(i=0; i<y+1-1; i++)
            for(l=i+1; l<y+1; l++)
            if(indeks[l]<indeks[i])
            {
                swap(indeks[i],indeks[l]);
                swap(O[i],O[l]);
                swap(A[i],A[l]);
                swap(AB[i],AB[l]);
                swap(B[i],B[l]);
            }
        cout << "moguce\n";
        for(i=0; i<N; i++)
            cout << O[i] << " " << A[i] << " " << B[i] << " " << AB[i] << "\n";
    }
    else cout << "nemoguce";
    
}