#include <bits/stdc++.h>
#include <string>

using namespace std;
int main()
{
    int N, O, A, B, AB, o, a, b, ab, value[1000];
    char type[1000];
    string temp;
    scanf("%d",&N);
    scanf("%d%d%d%d",&O, &A, &B, &AB);
    o=O;
    a=A;
    b=B;
    ab=AB;
    for(int i=0; i<N; i++)
    {
        cin>>temp;
        if (temp == "AB")
            type[i] = 'Z';
        else if (temp == "A")
            type[i] = 'A';
        else if (temp == "B")
            type[i] = 'B';
        else type[i] = 'O';
        scanf("%d", &value[i]);
        if(type[i] == 'A')
            A-=value[i];
        else if(type[i] == 'B')
            B-=value[i];
        else if(type[i] == 'O')
            O-=value[i];
        else
            AB-=value[i];
        if (O < 0)  break;
    }


    if(O>=0 && O+A>=0 && O+B>=0 && O+A+B>=0 && AB+A+B+O>=0)
    {
        printf("moguce\n");
        for(int i=0; i<N; i++)
        {
            switch(type[i])
            {
            case 'A':
                if(value[i]<a){
                    printf("0 %d 0 0\n",value[i]);
                a-=value[i];
                }
                else {
                        printf("%d %d 0 0\n",value[i]-a,a);
                        o-=value[i]+a;
                        a=0;
                }
                break;
            case 'B':
                if(value[i]<b){
                    printf("0 0 %d 0\n",value[i]);
                b-=value[i];
                }
                else {
                        printf("%d 0 %d 0\n",value[i]-b,b);
                        o-=value[i]+b;
                        b=0;
                }
                break;
            case 'O':
                printf("%d 0 0 0\n", value[i]);
                o-=value[i];
                break;
            default:
                if(value[i]<ab){
                    printf("0 0 0 %d\n",value[i]);
                ab-=value[i];
                }
                else if(A>0){
                    if(A+ab>=value[i]){
                        printf("0 %d 0 %d\n",value[i]-ab,ab);
                        ab=0;
                        A-=value[i]+ab;
                    }
                    else {
                        printf("%d %d 0 0\n",value[i]-A,A);
                        A=0;
                        o=o-value[i]+A;
                    }
                }
                else if(B>0){
                    if(B+ab>=value[i]){
                        printf("0 %d 0 %d\n",value[i]-ab,ab);
                        ab=0;
                        B-=value[i]+ab;
                    }
                    else {
                        printf("%d 0 %d 0\n",value[i]-B,B);
                        B=0;
                        o=o-value[i]+B;
                    }
                }
                else {
                    printf("%d 0 0 0\n",value[i]);
                    o-=value[i];
                }
                break;
            }
        }
    }
    else printf("nemoguce");
}