#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    int o,a,b,ab;
    scanf("%i",&n);
    scanf("%i %i %i %i",&o,&a,&b,&ab);
    pair<char[2],int> arr[n];

    //matrica resenja
    int rez[n][4];

    for (int i = 0; i < n; ++i) {
        scanf("%s %i",arr[i].first,&arr[i].second);
    }

    //IZRADA

    for (int i = 0; i < n; ++i) {
        if(!(strcmp(arr[i].first,"O")))
        {
            if((o-arr[i].second)<0)
            {
                printf("nemoguce");
                return 0;
            }
            else
            {
                o-=arr[i].second;
                rez[i][0]=arr[i].second;
                rez[i][1]=0;
                rez[i][2]=0;
                rez[i][3]=0;
            }
        }
        else if(!(strcmp(arr[i].first,"A")))
        {
            if((a-arr[i].second)<0)
            {
                rez[i][0]=0;
                rez[i][1]=a;
                rez[i][2]=0;
                rez[i][3]=0;
                arr[i].second-=a;
                a=0;
                if((o-arr[i].second)<0)
                {
                    printf("nemoguce");
                    return 0;
                }
                else
                {
                    o-=arr[i].second;
                    rez[i][0]=arr[i].second;
                }
            }
            else
            {
                a-=arr[i].second;
                rez[i][0]=0;
                rez[i][1]=arr[i].second;
                rez[i][2]=0;
                rez[i][3]=0;
            }
        }
        else if(!(strcmp(arr[i].first,"B")))
        {
            if((b-arr[i].second)<0)
            {
                rez[i][0]=0;
                rez[i][1]=0;
                rez[i][2]=b;
                rez[i][3]=0;
                arr[i].second-=b;
                b=0;
                if((o-arr[i].second)<0)
                {
                    printf("nemoguce");
                    return 0;
                }
                else
                {
                    o-=arr[i].second;
                    rez[i][0]=arr[i].second;
                }
            }
            else
            {
                b-=arr[i].second;
                rez[i][0]=0;
                rez[i][1]=0;
                rez[i][2]=arr[i].second;
                rez[i][3]=0;
            }
        }
        else if(!(strcmp(arr[i].first,"AB")))
        {
            {
                if((ab-arr[i].second)<0)
                {
                    rez[i][0]=0;
                    rez[i][1]=0;
                    rez[i][2]=0;
                    rez[i][3]=ab;
                    arr[i].second-=ab;
                    ab=0;
                    if((b-arr[i].second)<0)
                    {
                        rez[i][2]=b;
                        arr[i].second-=b;
                        b=0;
                        if((a-arr[i].second)<0)
                        {
                            rez[i][1]=a;
                            arr[i].second-=a;
                            a=0;
                            if((o-arr[i].second)<0)
                            {
                                printf("nemoguce");
                                return 0;
                            }
                            else
                            {
                                o-=arr[i].second;
                                rez[i][0]=arr[i].second;
                            }
                        }
                        else
                        {
                            a-=arr[i].second;
                            rez[i][1]=arr[i].second;
                        }
                    }
                    else
                    {
                        b-=arr[i].second;
                        rez[i][2]=arr[i].second;
                    }
                }
                else
                {
                    ab-=arr[i].second;
                    rez[i][0]=0;
                    rez[i][1]=0;
                    rez[i][2]=0;
                    rez[i][3]=arr[i].second;
                }
            }
        }
    }

    //ISPIS
    printf("moguce\n");
    for (int i = 0; i < n; ++i) {
        printf("%i %i %i %i\n",rez[i][0],rez[i][1],rez[i][2],rez[i][3]);
    }

    return 0;
}