#include <iostream>

int main()
{
    int n, o, a, b, ab, v = 0, k = 0;

    std::cin >> n >> o >> a >> b >> ab;
    int mat[n][4];
    v= a+b;

    for (int i = 0; i<n; i++)
        for (int j = 0; j<4; j++)
            mat[i][j] = 0;

    for (int i = 0; i<n && k==0; i++){
            int temp, temp1;
            std::string grupa;
            std::cin >> grupa;
            std::cin >> temp;

            if (grupa == "O")
                temp1 = -1;
            else if (grupa == "A")
                temp1 = -2;
            else if (grupa == "B")
                temp1 = -3;
            else
                temp1 = -4;


        switch(temp1){

            case -1:
                if (o-temp>=0){
                    mat[i][0] = temp;
                    o-=temp;
                }
                else
                    k++;
                break;
            case -2:
                if (a-temp>=0){
                    mat[i][1] = temp;
                    a-=temp;
                    v-=temp;
                }
                else if(a+o-temp>=0){
                    mat[i][1] = a;
                    mat[i][0] = temp-a;
                    a = 0;
                    o-= (temp-a);
                    v-=a;
                }
                else
                    k++;
                break;
            case -3:
                if (b-temp>=0){
                    mat[i][2] = temp;
                    b-=temp;
                    v-=temp;
                }
                else if(b+o-temp>=0){
                    mat[i][2] = b;
                    mat[i][0] = temp-b;
                    b = 0;
                    o-= (temp-b);
                    v-=b;
                }
                else
                    k++;
                break;
            case -4:
                if (ab-temp>=0){
                    mat[i][3] = temp;
                    ab-=temp;
                }
                else if ((ab+v)-temp>=0){
                    mat[i][3] = ab;
                    mat[i][2] = 1000001;
                    mat[i][1] = temp-ab;
                    ab = 0;
                }
                else if ((ab+v+o)-temp>=0){
                    mat[i][3] = ab;
                    mat[i][2] = b;
                    mat[i][1] = a;
                    ab = 0;
                    b = 0;
                    a = 0;
                    mat[i][0] = temp-(v+ab);
                    o-=(temp-(v+ab));
                }
                else
                    k++;
                break;
        }

        }

    if((k>0)|| (v<0)){
        std::cout << "nemoguce";
        return 0;
    }
    else
        for (int i = 0; i<n; i++){

            if (mat[i][2]==1000001){
                if (a>mat[i][1]){
                    a-=mat[i][1];
                    mat[i][2] = 0;
                }
                else if (b>mat[i][1]){
                    b=mat[i][1];
                    mat[i][2] = mat[i][1];
                    mat[i][1] = 0;
                }
                else{
                    if(a>b){
                        mat[i][1]=mat[i][1]-b;
                        mat[i][2]=b;
                        b=0;
                        a-=mat[i][1];
                    }else{
                        mat[i][2]=mat[i][1]-a;
                        mat[i][1]=a;
                        a=0;
                        b-=mat[i][2];
                    }
                }
            }


        }

    std::cout << "moguce\n";
    for (int i = 0; i<n; i++){
        for (int j = 0; j<4; j++)
            std::cout << mat[i][j] << " ";
    std::cout << "\n";
    }
    return 0;
}