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

int main()
{
    int n;
    int o,a,b,ab;
    cin>>n;
    cin>>o>>a>>b>>ab;
    vector<int> o1(n,0);
     vector<int> a1(n,0);
      vector<int> b1(n,0);
       vector<int> ab1(n,0);
    bool p = true;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        int k;
        cin>>k;

        if(s=="O")
        {
            if(o>=k)
            {
                o-=k;
                o1[i]=k;
            }
            else p=false;
        }
        else if(s=="A" || s=="B")
        {
            if(s=="A")
            {
                if(a>=k)
                {
                    a-=k;
                    a1[i]=k;
                }
                else if(a+o>=k)
                {
                    k-=a;
                    o-=k;
                    o1[i]=k; a1[i]=a;
                    //cout<<k<<" "<<a<<" 0 0";
                    a=0;
                }
                else p=false;
            }

            if(s=="B")
            {
                if(b>=k)
                {
                    b-=k;
                    b1[i]=k;
                   // cout<<"0 0 "<<k<<" 0";
                }
                else if(b+o>=k)
                {
                    k-=b;
                    o-=k;
                    o1[i]=k; b1[i]=b;
                //    cout<<k<<" 0 "<<b<<"0";
                    b=0;
                }
                else p=false;
            }
        }
            if(s=="AB")
            {
                if(ab>=k)
                {
                    ab-=k;
                    ab1[i]=k;
                }
                else if(a>b && a+ab>=k)
                {
                    k-=ab;
                    ab1[i]=ab;
                    ab=0;
                    a-=k;
                    a1[i]=k;
                }
                else if(b+ab>=k)
                {
                    k-=ab;
                    ab1[i]=ab;
                    ab=0;
                    b-=k;
                    b1[i]=k;
                }
                else if(a+b+ab>=k)
                {
                    k=k-ab-a;
                    ab1[i]=0;
                    ab=0;
                    a1[i]=a;
                    a=0;
                    b1[i]=k;
                }
                else if(a+b+ab+o>=k)
                {
                    k=k-ab-a-b;
                    ab1[i]=0;
                    ab=0;
                    a1[i]=a;
                    a=0;
                    b1[i]=0;
                    b=0;
                    o1[i]=k;
                }
                else p=false;
            }

    }
    if(p==true)
    {
        cout<<"moguce"
        for(int i=0;i<n;i++)
        {
            cout<<o1[i]<<" "<<a1[i]<<" "<<b1[i]<<" "<<ab1[i]<<endl;
        }
    }
    else cout<<"nemoguce";
    return 0;
}