#include <bits/stdc++.h>

using namespace std;

struct covek
{
public:
    string grupa;
    int a=0,b=0,ab=0,o=0,k;
    bool dalijeab=false;
};
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n,o,a,b,ab;
    cin>>n>>o>>a>>b>>ab;
    covek x[n];
    bool p=true;
    for(int i=0;i<n&&p;i++)
    {
        cin>>x[i].grupa>>x[i].k;
        if(x[i].grupa=="O")
        {
            x[i].o=x[i].k;
            o-=x[i].o;
            if(o<0) p=false;
        }
        else if(x[i].grupa=="A")
        {
            if(x[i].k>a)
            {
                x[i].a=a;
                a=0;
                x[i].ab=x[i].k-x[i].a;
                ab=ab-x[i].k+x[i].a;
                if(ab<0) p=false;
            }
            else
            {
                x[i].a=x[i].k;
                a-=x[i].a;
            }
        }
        else if(x[i].grupa=="B")
        {
             if(x[i].k>b)
            {
                x[i].b=b;
                b=0;
                x[i].ab=x[i].k-x[i].b;
                ab=ab-x[i].k+x[i].b;
                if(ab<0) p=false;
            }
            else
            {
                x[i].b=x[i].k;
                b-=x[i].b;
            }
        }
        else x[i].dalijeab=true;
    }
    for(int i=0;i<n&&p;i++)
    {
        if(x[i].dalijeab)
        {
            if(x[i].k>a)
            {
                x[i].a=a;
                a=0;
                if(x[i].k-x[i].a>b)
                {
                    x[i].b=b;
                    b=0;
                    if(x[i].k-x[i].a-x[i].b>ab)
                    {
                        x[i].ab=ab;
                        ab=0;
                        if(x[i].k-x[i].a-x[i].b-x[i].ab>o)
                        {
                            p=false;
                        }
                        else
                        {
                            x[i].o=x[i].k-x[i].a-x[i].b-x[i].ab;
                            o=o-(x[i].k-x[i].a-x[i].b-x[i].ab);
                        }
                    }
                    else
                    {
                        x[i].b=x[i].k-x[i].a-x[i].b;
                        b=b-x[i].k+x[i].a+x[i].b;
                    }
                }
                else
                {
                    x[i].b=x[i].k-x[i].a;
                    b=b-x[i].k+x[i].a;
                }
            }
            else
            {
                x[i].a=x[i].k;
                a-=x[i].k;
            }
        }
    }
    if(p)
    {
        cout<<"moguce\n";
        for(int i=0;i<n;i++)
        {
            cout<<x[i].o<<" "<<x[i].a<<" "<<x[i].b<<" "<<x[i].ab<<"\n";
        }
    }
    else cout<<"nemoguce";
}