#include <bits/stdc++.h>

using namespace std;

struct pacijenat
{
    string kg;
    int jed,o=0,a=0,b=0,ab=0;
};

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

    int n,q=0,o,a,b,ab;
    bool jess=true;

    cin >> n;
    cin >> o;
    cin >> a;
    cin >> b;
    cin >> ab;

    vector <pacijenat> v(n);
    vector <int> imbecil(n);

    for(int i=0; i<n; i++)
    {
        cin >> v[i].kg;
        cin >> v[i].jed;

        if(v[i].kg=="O")
        {
            v[i].o=v[i].jed;
            o-=v[i].jed;
        }
        else if(v[i].kg=="A")
        {
            v[i].a=v[i].jed;
            a-=v[i].jed;

            if(a<0)
            {
                o+=a;
                v[i].o+=0-a;
                v[i].a+=a;
                a=0;
            }
        }
        else if(v[i].kg=="B")
        {
            v[i].b=v[i].jed;
            b-=v[i].jed;

            if(b<0)
            {
                o+=b;
                v[i].o+=0-b;
                v[i].b+=b;
                b=0;
            }
        }
        else
        {
            imbecil[q]=i;
            q++;
        }

        if(o<0)
        {
            jess=false;
        }
    }

    if(!jess)
    {
        cout << "nemoguce" << endl;

        return 0;
    }

    for(int i=0; jess && i<q; i++)
    {
        if(v[imbecil[i]].jed<=ab)
        {
            ab-=v[imbecil[i]].jed;
            v[imbecil[i]].ab+=v[imbecil[i]].jed;
            v[imbecil[i]].jed=0;
        }
        else
        {
            v[imbecil[i]].ab+=ab;
            v[imbecil[i]].jed-=ab;
            ab=0;

            if(v[imbecil[i]].jed<=b)
            {
                b-=v[imbecil[i]].jed;
                v[imbecil[i]].b+=v[imbecil[i]].jed;
                v[imbecil[i]].jed=0;
            }
            else
            {
                v[imbecil[i]].b+=b;
                v[imbecil[i]].jed-=b;
                b=0;

                if(v[imbecil[i]].jed<=a)
                {
                    a-=v[imbecil[i]].jed;
                    v[imbecil[i]].a+=v[imbecil[i]].jed;
                    v[imbecil[i]].jed=0;
                }
                else
                {
                    v[imbecil[i]].a+=a;
                    v[imbecil[i]].jed-=a;
                    a=0;

                    if(v[imbecil[i]].jed<=o)
                    {
                        o-=v[imbecil[i]].jed;
                        v[imbecil[i]].o+=v[imbecil[i]].jed;
                        v[imbecil[i]].jed=0;
                    }
                    else
                    {
                        jess=false;
                    }
                }
            }
        }
    }

    if(jess)
    {
        cout << "moguce" << endl;

        for(int i=0; i<n; i++)
        {
            cout << v[i].o << " " << v[i].a << " " << v[i].b << " " << v[i].ab << endl;
        }
    }
    else
    {
        cout << "nemoguce" << endl;
    }

    return 0;
}