#include <bits/stdc++.h>

using namespace std;


struct Tip
{
    int krv;
    int p;
    int redosled;
    int o;
    int a;
    int b;
    int ab;
};

bool sortiraj(Tip a, Tip b)
{
    return a.krv<=b.krv;
}

bool sort2(Tip a, Tip b)
{
    return a.redosled<b.redosled;
}

int main()
{
    int n,o,a,b,ab;
    cin>>n>>o>>a>>b>>ab;
    int k[4];
    for(int i=0;i<4;i++) k[i]=0;
    Tip typ[n];
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s>>typ[i].p;
        typ[i].redosled=i;
        typ[i].o=0;
        typ[i].a=0;
        typ[i].b=0;
        typ[i].ab=0;
        if(s=="O")
        {
            typ[i].krv=0;
            k[0]+=typ[i].p;
        }
        else if(s=="A")
        {
            typ[i].krv=1;
            k[1]+=typ[i].p;
        }
        else if(s=="B")
        {
            typ[i].krv=2;
            k[2]+=typ[i].p;
        }
        else
        {
            typ[i].krv=3;
            k[3]+=typ[i].p;
        }
    }
    sort(typ,typ+n,sortiraj);
    if(o>=k[0] && o+a+b+ab>=k[0]+k[1]+k[2]+k[3])
    {
        if(abs(max(k[1]-a,0))+abs(max(k[2]-b,0))<=o-k[0])
        {
            cout<<"moguce"<<endl;
            for(int i=0;i<n;i++)
            {
                if(typ[i].krv==0)
                {
                    typ[i].o=typ[i].p;
                    typ[i].a=0; typ[i].b=0; typ[i].ab=0;
                    o-=typ[i].p;
                }
                if(typ[i].krv==1)
                {
                    if(a < typ[i].p)
                    {
                        typ[i].o=typ[i].p-a;
                        typ[i].a=a;
                        typ[i].b=0; typ[i].ab=0;
                        o-=typ[i].p-a;
                        a=0;
                    }
                    else
                    {
                        typ[i].o=0;
                        typ[i].a=typ[i].p;
                        typ[i].b=0; typ[i].ab=0;
                        a-=typ[i].p;
                    }
                }
                if(typ[i].krv==2)
                {
                    if(b<typ[i].p)
                    {
                        typ[i].o=typ[i].p-b;
                        typ[i].a=0;
                        typ[i].b=b;
                        typ[i].ab=0;
                        o-=(typ[i].p-b);
                        b=0;
                    }
                    else
                    {
                        typ[i].o=0; typ[i].a=0;
                        typ[i].b=typ[i].p;
                        typ[i].ab=0;
                        b-=typ[i].p;
                    }
                }
                if(typ[i].krv==3)
                {
                    if(ab<typ[i].p)
                    {
                        if(a>=typ[i].p-ab)
                        {
                            typ[i].o=0;
                            typ[i].a=typ[i].p-ab;
                            typ[i].b=0;
                            typ[i].ab=ab;
                            a-=typ[i].p-ab;
                            ab=0;
                        }
                        else if(b>=typ[i].p-ab-a)
                        {
                            typ[i].o=0;
                            typ[i].a=a;
                            typ[i].b=typ[i].p-ab-a;
                            typ[i].ab=ab;
                            a=0;
                            ab=0;
                        }
                        else
                        {
                            typ[i].o=typ[i].p-ab-a-b;
                            typ[i].a=a;
                            typ[i].b=typ[i].p-ab-a;
                            typ[i].ab=ab;
                            o-=typ[i].p-ab-a-b;
                            a=0;
                            ab=0;
                            b=0;
                        }
                    }
                    else
                    {
                        typ[i].o=0; typ[i].a=0; typ[i].b=0;
                        typ[i].ab=typ[i].p;
                        ab-=typ[i].p;
                    }
                }
            }
            sort(typ,typ+n,sort2);
            for(int i=0;i<n;i++) cout<<typ[i].o<<" "<<typ[i].a<<" "<<typ[i].b<<" "<<typ[i].ab<<endl;
        }
        else cout<<"nemoguce";
    }
    else cout<<"nemoguce";
    return 0;
}