#include<iostream>
#include<cstring>
using namespace std;
struct pac{
    int bro,po;
};
bool jednako(char s[],char c){
    if(strlen(s)>1) return false;
    if(s[0]==c) return true;
    return false;
}
int main()
{
    int n,o,a,b,ab,br,ko=0,ka=0,kb=0,kab=0;
    cin>>n>>o>>a>>b>>ab;
    char s[2];
    pac on[n],an[n],bn[n],abn[n],m;
    int x[n][4],p;
    bool moguce=true;
    for(int i=0;i<n;i++){
        cin>>s;
        cin>>br;
        m.bro=br;
        m.po=i;
        if(jednako(s,'O')) on[ko++]=m;
        else if(jednako(s,'A')) an[ka++]=m;
        else if(jednako(s,'B')) bn[kb++]=m;
        else abn[kab++]=m;
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<4;j++) x[i][j]=0;
    for(int i=0;i<ko&&moguce;i++)
    {
        br=on[i].bro;
        p=on[i].po;
        if(o>=br){
            o-=br;
            x[p][0]=br;
        }
        else moguce=false;
    }
    for(int i=0;i<ka&&moguce;i++)
    {
        br=an[i].bro;
        p=an[i].po;
        if(a+o>=br){
            if(a>=br){
                a-=br;
                x[p][1]=br;
            }
            else{
                x[p][1]=a;
                br-=a;
                a=0;
                o-=br;
                x[p][0]=br;
            }
        }
        else moguce=false;
    }
    for(int i=0;i<kb&&moguce;i++)
    {
        br=bn[i].bro;
        p=bn[i].po;
        if(b+o>=br){
            if(b>=br){
                b-=br;
                x[p][2]=br;
            }
            else{
                x[p][2]=b;
                br-=b;
                b=0;
                o-=br;
                x[p][0]=br;
            }
        }
        else moguce=false;
    }
    for(int i=0;i<kab&&moguce;i++)
    {
        br=abn[i].bro;
        p=abn[i].po;
        if(a+b+o+ab>=br){
            if(ab>=br){
                ab-=br;
                x[p][3]=br;
            }
            else{
                x[p][3]=ab;
                br-=ab;
                ab=0;
                if(a>=br){
                    a-=br;
                    x[p][1]=br;
                }
                else{
                    x[p][1]=a;
                    br-=a;
                    a=0;
                    if(b>=br){
                        b-=br;
                        x[p][2]=br;
                    }
                    else{
                        x[p][2]=b;
                        br-=b;
                        b=0;
                        o-=br;
                        x[p][0]=br;
                    }
                }
            }
        }
        else moguce=false;
    }
    if(!moguce) cout<<"nemoguce";
    else{
        cout<<"moguce"<<endl;
        for(int i=0;i<n;i++){
            for(int j=0;j<4;j++)
                cout<<x[i][j]<<' ';
            cout<<endl;
        }
    }
    return 0;
}