#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
struct pac
{
    string bld;
    int jed;
};
struct zal
{
    int ap, bp, op, abp;
};
 void kopiraj(char ch[], string str)
{
    for(int r = 0; str[r]!=0; r++)
        ch[r]=str[r];
}
bool vidi(string s, char a)
{
    return(s[0]==a);
}
bool vidi2(string s, string x)
{
    int w=0;
    if(s[0]==x[0])
        w=1;
    if(w)
    {
        if(s[1]==x[1])return true;
    }
    return false;
}
void ispis(zal x[], int n)
{
    for(int m=0;m<n;m++)
        cout<<x[m].op<<' '<<x[m].ap<<' '<<x[m].bp<<' '<<x[m].abp<<endl;
}
void krv(pac p[], int n, zal x[], int a, int b, int o, int ab, bool&ima)
{
        int i;
        for(i=0;i<n;i++)
        {
            if(vidi(p[i].bld,'O'))
                while(o>0 and p[i].jed>0){o--;p[i].jed--;x[i].op++;};
                if(o==0 and p[i].jed!=0) ima=false;
        }
        if(ima)
            for(i=0;i<n;i++)
        {
            if(vidi(p[i].bld,'A'))
                while(a>0 and p[i].jed>0){a--;p[i].jed--;x[i].ap++;};
                if(a==0)
                {
                    while(o>0 and p[i].jed>0){o--;p[i].jed--;x[i].op++;};
                    if(o==0 and p[i].jed!=0) ima=false;
                }
        }
        if(ima)
            for(i=0;i<n;i++)
        {
            if(vidi(p[i].bld,'B'))
                while(b>0 and p[i].jed>0){b--;p[i].jed--;x[i].bp++;};
                if(b==0)
                {
                    while(o>0 and p[i].jed>0){o--;p[i].jed--;x[i].op++;};
                    if(o==0 and p[i].jed!=0) ima=false;
                }
        }
        if(ima)
            for(i=0;i<n;i++)
        {
            if(vidi2(p[i].bld,"AB"))
                while(ab>0 and p[i].jed>0){ab--;p[i].jed--;x[i].abp++;};
                if(ab==0 and p[i].jed>0)
                {
                    while(a>0 and p[i].jed>0){a--;p[i].jed--;x[i].ap++;};
                    if(a==0 and p[i].jed!=0)
                    {
                        while(b>0 and p[i].jed>0){b--;p[i].jed--;x[i].bp++;};
                        if(b==0 and p[i].jed!=0)
                            {
                              while(o>0 and p[i].jed>0){o--;p[i].jed--;x[i].op++;};
                              if(o==0 and p[i].jed!=0) ima=false;
                            }
                    }
                }
        }

}
int main()
    {
        pac p[10000];
        zal x[10000];
        int ab,a, b, o, n, s=0;
        string q;
        bool mhm=true;
        cin>>n;
        cin>>o>>a>>b>>ab;
        for(int j = 0; j<n; j++)
            {
                getline(cin, q);
                char e[20];
                kopiraj(e, q);
                char *f;
                f = strchr(e,' ');
                *f=0;
                kopiraj(e, p[j].bld);
                p[j].jed = atoi(f+1);
                s+=p[j].jed;
            }
        if(s>a+b+ab+o) cout<<"nemoguce";
        else
        {
            krv(p, n, x, a, b, o, ab, mhm);
            if(!mhm) cout<<"nemoguce";
            else
            {
                cout<<"moguce"<<endl;
                ispis(x, n);
            }
        }
    }