#include <stdio.h>
#include <iostream>
using namespace std;
int ind[10000],A[10000],B[10000],O[10000],AB[10000];
int main()
{
    int n,o,a,b,ab,i,krv[10000];
    string grupa[10000];
    cin >> n >> o >> a >> b >> ab;
    for(i=0;i<n;i++)
    {
        cin >> grupa[i] >> krv[i];
        if(grupa[i]=="O")
        {
            o=o-krv[i];
            ind[i]=1;
            O[i]=krv[i];
        }

    }
    if(o<0)
    {
        cout << "nemoguce";
        return 0;
    }
    for(i=0;i<n;i++)
    {
        if(grupa[i]=="A")
        {
            if(a>=krv[i])
            {
                a=a-krv[i];
                ind[i]=1;
                A[i]=krv[i];
            }
            else
            {
                A[i]=a;
                a=0;
                if(o>=krv[i]-A[i])
                {
                    O[i]=krv[i]-A[i];
                    ind[i]=1;
                    o=o-O[i];
                }
                else
                {
                    cout << "nemoguce";
                    return 0;
                }

            }


        }
        if(grupa[i]=="B")
        {
            if(b>=krv[i])
            {
                b=b-krv[i];
                ind[i]=1;
                B[i]=krv[i];
            }
            else
            {
                B[i]=b;
                b=0;
                if(o>=krv[i]-B[i])
                {
                    O[i]=krv[i]-B[i];
                    ind[i]=1;
                    o=o-O[i];
                }
                else
                {
                    cout << "nemoguce";
                    return 0;
                }

            }


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

        if(grupa[i]=="AB")
        {
           if(ab>=krv[i])
           {
               AB[i]=krv[i];
               ind[i]=1;
               ab=ab-krv[i];
           }
           else
           {
               AB[i]=ab;
               ab=0;
               krv[i]=krv[i]-AB[i];
               if(a>=krv[i])
               {
                   A[i]=krv[i];
                   ind[i]=1;
                   a-=krv[i];
               }
               else
               {
                   A[i]=a;
                   a=0;
                   krv[i]=krv[i]-A[i];
                   if(b>=krv[i])
                   {
                        B[i]=krv[i];
                        ind[i]=1;
                        b-=krv[i];
                   }
                   else
                   {
                       B[i]=b;
                       b=0;
                       krv[i]=krv[i]-b;
                       if(o>=krv[i])
                       {
                           O[i]=krv[i];
                           ind[i]=1;
                           o-=krv[i];
                       }
                       else
                       {
                           cout << "nemoguce";
                           return 0;
                       }
                   }

               }
           }
        }

    }
    cout << "moguce\n";
    for(i=0;i<n;i++)
    {
       cout << O[i] << " " << A[i] << " "<< B[i] << " "<< AB[i] << "\n";
    }

    return 0;
}