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

int main()
{
    int n, O, A, B, AB, k, kO, kA, kB;
    char gr[2];
    char *grs[100][2];
    int ks[100];
    bool nmg = false;
    int rez[4];
    int rezs[100][4];
    scanf("%d %d %d %d %d",& n, &O, &A, &B, &AB);
    for(int i=0;i<n;i++){
        scanf("%s", gr);

        strcpy(grs[i], gr);

        scanf("%d",&k);
        ks[i] = k;
    }

    for(int i=0;i<n;i++){
       //printf("s:%s, k:%d\n", grs[i],k);
        if(strcmp(grs[i],"O")==0){
            if(O-ks[i]>=0){
                O -= ks[i];
                //printf("%d 0 0 0\n", ks[i]);
                rez[0] = ks[i];
                rez[1] = 0;
                rez[2] = 0;
                rez[3] = 0;
            }
            else{
                nmg = true;
                //break;
            }
        }else if(strcmp(grs[i],"A")==0){
            if(A-ks[i] >=0){
                A -= ks[i];
                //printf("0 %d 0 0\n", ks[i]);
                rez[0] = 0;
                rez[1] = ks[i];
                rez[2] = 0;
                rez[3] = 0;

            }
            else{
                int kO = ks[i] - A;
                if(O-kO>=0){
                O -= kO;
                //printf("%d %d 0 0\n", kO, A);
                rez[0] = kO;
                rez[1] = A;
                rez[2] = 0;
                rez[3] = 0;
                A = 0;

                }
                else{
                    nmg = true;
                    //break;
                }
            }
        }else if(strcmp(grs[i],"B")==0){
            if(B-ks[i] >=0){
                B -= ks[i];
                //printf("0 0 %d 0\n", ks[i]);
                rez[0] = 0;
                rez[1] = 0;
                rez[2] = ks[i];
                rez[3] = 0;
            }
            else{
                int kO = ks[i] - B;
                if(O-kO>=0){
                O -= kO;
                //printf("%d 0 %d 0\n", kO, B);
                rez[0] = kO;
                rez[1] = 0;
                rez[2] = B;
                rez[3] = 0;
                B = 0;

                }
                else{
                    nmg = true;
                    //break;
                }
            }
        }else if(strcmp(grs[i],"AB")==0){
            if(AB-ks[i]>=0){
                AB -= ks[i];
                //printf("0 0 0 %d\n", ks[i]);
                rez[0] = 0;
                rez[1] = 0;
                rez[2] = 0;
                rez[3] = ks[i];
            }
            else{
                if(A>=B){
                    int kA = ks[i] - AB;
                    if(A-kA>=0){
                        A -= kA;
                        //printf("0 %d 0 %d\n", kA, AB);
                        rez[0] = 0;
                        rez[1] = kA;
                        rez[2] = 0;
                        rez[3] = AB;

                    }
                    else{
                        int kB = kA-A;

                        if(B-kB>=0){
                            B -= kB;
                            //printf("0 %d %d %d\n", A, kB, AB);
                            rez[0] = 0;
                            rez[1] = A;
                            rez[2] = kB;
                            rez[3] = AB;

                        }
                        else{
                            int kO = kB-B;
                            if(O-kO>=0){
                                O -= kO;
                                //printf("%d %d %d %d\n",kO, A, B, AB);
                                rez[0] = kO;
                                rez[1] = A;
                                rez[2] = B;
                                rez[3] = AB;
                                B =0;

                            }
                            else{
                                nmg = true;
                                //break;
                            }
                        }
                        A =0;
                    }
                }
                else{
                    int kB = ks[i] - AB;
                    if(B-kB>=0){
                    B -= kB;
                    //printf("0 0 %d %d\n", kB, AB);
                    rez[0] = 0;
                    rez[1] = 0;
                    rez[2] = kB;
                    rez[3] = AB;
                    }
                    else{
                        int kA = kB-B;
                        if(A-kA>=0){
                            A -= kA;
                            //printf("0 %d %d %d\n", kA, B, AB);
                            rez[0] = 0;
                            rez[1] = kA;
                            rez[2] = B;
                            rez[3] = AB;
                            B = 0;

                        }
                        else{
                            int kO = kA-A;

                            if(O-kO>=0){
                                O -= kO;
                                //printf("%d %d %d %d\n",kO, A, B,AB);
                                rez[0] = kO;
                                rez[1] = A;
                                rez[2] = B;
                                rez[3] = AB;
                            }
                            else{
                                nmg = true;
                                //break;
                            }
                            A = 0;
                        }
                    }
                }
            }
        }

        if(nmg == true){
            break;
        }
        for(int j=0; j<4;j++){
            rezs[i][j] = rez[j];
        }

    }
    if(nmg == true){
        printf("Nemoguce");}
    else{
        printf("Moguce\n");
        for(int i=0;i<n;i++){
            for(int k=0; k<4; k++){
                printf("%d ",rezs[i][k]);
        }
        printf("\n");
        }


    }
    return 0;
}