#include <iostream>
#include<vector>
using namespace std;

int main()
{
    int n,o,a,b,ab,j=0;
    cin>>n>>o>>a>>b>>ab;
     vector<string>d(n);
      vector<int>c(n);
    vector<int>ro(n);
    vector<int>ra(n);
    vector<int>rb(n);
    vector<int>rab(n);
    for(int i=0;i<n;i++)
    {
    cin>>d[i];
    cin>> c[i];
    if(d[i]=="O")
         {
         if(o>=c[i])
         {
             o-=c[i];
             ro[i]=c[i];

         }
          else j=1;
       }

        if(d[i]=="A")
       {
         if(a>=c[i])
         {
             a-=c[i];
             ra[i]=c[i];

         }
         else
         {
            c[i]-=a;
            ra[i]=a;
            a=0;

            if(o>=c[i])
            {
                o-=c[i];
                ro[i]=c[i];
            }
            else j=1;
         }
       }
        if(d[i]=="B")
       {
         if(b>=c[i])
         {
             b-=c[i];
             rb[i]=c[i];

         }
         else
         {
            c[i]-=b;
            rb[i]=b;
            b=0;

            if(o>=c[i])
            {
                o-=c[i];
                ro[i]=c[i];
            }
            else j=1;
         }
       }
    }


        for(int i=0;i<n;i++)
     {

  if(d[i]=="AB")
       {
         if(ab>=c[i])
         {
             ab-=c[i];
             rab[i]=c[i];

         }
         else
         {
            c[i]-=ab;
            rab[i]=ab;
            ab=0;
             if(a>=c[i])
            {
                a-=c[i];
                ra[i]=c[i];
            }
           else  if(b>=c[i])
            {
                b-=c[i];
                rb[i]=c[i];
            }
           else if(o>=c[i])
            {
                o-=c[i];
                ro[i]=c[i];
            }
            else if(a+b+o>=c[i])
            {
                c[i]-=a;
                ra[i]=a;
                a=0;
                 if(b>c[i])
                {
                    b-=c[i];
                    rb[i]=c[i];
                }
                else
                {
                    c[i]-=b;
                    rb[i]=b;
                    b=0;
                    o-=c[i];
                    ro[i]=c[i];
                }
            }
            else{j=1;break;}
         }
       }
     }
     if(j==1)cout<<"nemoguce";
    else
     {
            cout<<"moguce"<<endl;
            for(int i=0;i<n;i++)cout<<ro[i]<<" "<<ra[i]<<" "<<rb[i]<<" "<<rab[i]<<endl;
     }

    return 0;
}