#include <stdio.h>
#include <stdlib.h>

int main()
{
    int N,O,A,B,AB,i,m1,m2,m3,m4;
    scanf("%d",&N);
    int o[N],a[N],b[N],ab[N],kell[N];
    char ver[N];
    scanf("%d %d %d %d",o,a,b,ab);
    fflush(stdin);
    for(i=0;i<N;i++)
    {
        scanf("%c %d",&ver[i],&kell[i]);

    }

    for(i=0;i<N;i++)
    {
       if( ver[i]=='A')
       {
           A=A-kell[i];
                if(A<0)
                {
                    O=O+A;
                    if(O<0)
                    {
                       m1=0;
                    }
                    else{
                        o[i]=0-A;
                        a[i]=kell[i]+A;
                    }
                }
                else{
                     a[i]=kell[i];
                    m1=1;
                }
                break;
       }

        else if(ver[i]=='B')
            {
                 B=B-kell[i];
                if(B<0)
                {
                    O=O+B;
                    if(O<0)
                    {
                       m2=0;
                    }
                    else{
                        o[i]=0-B;
                        b[i]=kell[i]+B;
                    }
                }
                else{
                        b[i]=kell[i];
                    m2=1;
                }
                break;
            }


        else if(ver[i]=='O')
            {
                 O=O-kell[i];
                    if(O<0)
                        {
                            m3=0;
                        }
                    else{
                            m3=1;
                            o[i]=kell[i];
                        }

            }
        else {
                AB=AB-kell[i];
        if(AB<0)
        {
             A=A+AB;
                    if(A<0)
                        {
                            B=B+A;
                            if(B<0)
                            {
                                O=O+B;
                                if(O<0)
                                {
                                    m4=0;
                                }
                                else{
                                    m4=1;
                                    ab[i]=kell[i]+AB;
                                    a[i]=ab[i]+A;
                                    b[i]=0-A+B;
                                    o[i]=kell[i]-ab[i]-a[i]-b[i];

                                }
                            }
                            else{
                                m4=1;
                                ab[i]=kell[i]+AB;
                                a[i]=kell[i]-ab[i]+A;
                                b[i]=kell[i]-ab[i]-a[i];
                            }

                        }

                    else{
                         m4=1;
                         a[i]= abs(AB);
                         ab[i]=kell[i]-abs(AB);
                    }
                break;
        }
        else{
            ab[i]=kell[i];
        }

            }

    }

    if( (m1==1)&&(m2==1)&&(m3==1)&&(m4==1))
    {
        printf("moguce");
        for(i=0;i<N;i++)
        {
            printf("%d %d %d %d",o[i],a[i],b[i],ab[i]);
        }

    }
    else{
        printf("nemoguce");
    }
    return 0;
}