#include <iostream>
#include <string>
using namespace std;
struct pacijent
{
  int o;
  int a;
  int b;
  int ab;
};
int main()
{
    pacijent p[10002];
    int n,i,io,ia,ib,iab,k,l,ta,to,tb,tab,o[10002],a[10002],b[10002],ab[10002];
    string y;
    bool moze=true;
    io=0;
    ia=0;
    ib=0;
    iab=0;
    cin>>n;
    cin>>to>>ta>>tb>>tab;
    for (i=0;i<n;i++)
    {
        cin >>y>>k;
        if (y=="O")
        {
        if (to>=k)
        {
            p[i].o=k;
            p[i].a=0;
            p[i].b=0;
            p[i].ab=0;
            to=to-k;
        }
        else
        moze=false;
        }
        
        
        
        else if (y=="A")
        {
        if (ta>=k)
        {
            p[i].o=0;
            p[i].a=k;
            p[i].b=0;
            p[i].ab=0;
            ta=ta-k;
        }
        else if(ta+to>=k)
        {
            p[i].o=k-ta;
            p[i].a=ta;
            p[i].b=0;
            p[i].ab=0;
            ta=0;
            to = to-(k-ta);
        }
        else
        moze=false;
        }
        else if (y=="B")
        {
        if (tb>=k)
        {
            p[i].o=0;
            p[i].a=0;
            p[i].b=k;
            p[i].ab=0;
            tb=tb-k;
        }
        else if (tb+to>=k)
        {
            p[i].o=k-tb;
            p[i].a=0;
            p[i].b=tb;
            p[i].ab=0;
            tb=0;
            to = to-(k-tb);
        }
        else
        moze=false;
        }
        else if (y=="AB")
        {
        ab[iab]=k;
        a[iab]=i;
        iab++;
        
        }
    }
    for (i=0;i<iab;i++)
    {
        if (tab>=ab[i])
        {
            p[a[i]].o=0;
            p[a[i]].a=0;
            p[a[i]].b=0;
            p[a[i]].ab=ab[i];
            tab=tab-ab[i];
        }
        else if (tab+tb>=ab[i])
        {
            p[a[i]].o=0;
            p[a[i]].a=0;
            p[a[i]].b=ab[i]-tab;
            p[a[i]].ab=tab;
            tab=0;
            tb=tb-(ab[i]-tab);
        }
        else if (tab+ta>=ab[i])
        {
            p[a[i]].o=0;
            p[a[i]].a=ab[i]-tab;
            p[a[i]].b=0;
            p[a[i]].ab=tab;
            tab=0;
            ta=ta-(ab[i]-tab);
        }
        else if (tab+ta+tb>=ab[i])
        {
            if (ta>=tb)
            {
            p[a[i]].o=0;
            p[a[i]].a=ab[i]-tab-tb;
            p[a[i]].b=tb;
            p[a[i]].ab=tab;
            tab=0;
            tb=0;
            ta=ta-(ab[i]-tab-tb);
            }
            else
            {
                
            p[a[i]].o=0;
            p[a[i]].a=ta;
            p[a[i]].b=ab[i]-tab-ta;
            p[a[i]].ab=tab;
            tab=0;
            ta=0;
            tb=tb-(ab[i]-tab-ta);
            
            }
        }
        else if (tab+ta+tb+to>=ab[i])
        {
            p[a[i]].o=ab[i]-tab-tb-ta;
            p[a[i]].a=ta;
            p[a[i]].b=tb;
            p[a[i]].ab=tab;
            tab=0;
            tb=0;
            ta=0;
            to=to-(ab[i]-tab-tb-ta);
        }
        else 
        moze = false;
    }
    if (moze==false)
    cout <<"nemoguce";
    else
    {
        cout <<"moguce"<<endl;
        for(i=0;i<n;i++)
        {
            cout <<p[i].o<<" "<<p[i].a<<" "<<p[i].b<<" "<<p[i].ab<<endl;
        }
    }
    
}