#include <iostream>
#include <string.h>

using namespace std;


struct pacijent
{
    char grupa[3];
    int kol;
};

void unos(pacijent p[],unsigned n)
{
    for(int i=0;i<n;i++)
    {
        cin>>p[i].grupa>>p[i].kol;
    }
}

int funk(pacijent p[],unsigned o,unsigned a,unsigned b,unsigned n)
{
    if(p[0].kol+p[1].kol+p[2].kol<=o+a+b)
    {
        cout<<"moguce"<<endl;
    for(int i=0;i<n;i++)
    {

        if(strcmp(p[i].grupa,"O")==0)
        {
            if(p[i].kol<=o)
            {
                o=o-p[i].kol;
                cout<<p[i].kol<<" "<<0<<" "<<0<<" "<<0<<endl;
            }
            else
            {

                break;
            }

        }



        else if(strcmp(p[i].grupa,"A")==0)
        {
            if(p[i].kol<=a)
            {
                a=a-p[i].kol;
                cout<<0<<" "<<p[i].kol<<" "<<0<<" "<<0<<endl;

            }
            else if(p[i].kol>=a && p[i].kol<=o)
            {
                a=0;
                o=o-p[i].kol;
                cout<<p[i].kol<<" "<<0<<" "<<0<<" "<<0<<endl;
            }
            else
            {


                break;
            }
        }



        else if(strcmp(p[i].grupa,"B")==0)
        {
            if(p[i].kol<=b)
            {
                b=b-p[i].kol;
                cout<<0<<" "<<0<<" "<<p[i].kol<<" "<<0<<endl;
            }
            else if(p[i].kol>=a && p[i].kol<=o)
            {
                b=0;
                o=o-p[i].kol;
                cout<<p[i].kol<<" "<<0<<" "<<0<<" "<<0<<endl;
            }
            else
            {


                break;
            }

        }


    }

    }
    else
        cout<<"nemoguce";


}



int main()
{
    unsigned n,o,a,b;
    int okidac;
    cin>>n>>o>>a>>b;
    pacijent p[n];
    unos(p,n);
    funk(p,o,a,b,n);

    return 0;
}