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

int main()
{
    int n;
    int o,a,b,ab;
    cin>>n;
    cin>>o>>a>>b>>ab;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        int k;
        cin>>k;

        if(s=="O")
        {
            if(o>=k)
            {
                o-=k;
                cout<<k<<" 0 0 0"<<endl;
            }
            else cout<<"nemoguce";
        }
        else if(s=="A" || s=="B")
        {
            if(s=="A")
            {
                if(a>=k)
                {
                    a-=k;
                    cout<<"0 "<<k<<" 0 0";
                }
                else if(a+o>=k)
                {
                    k-=a;
                    o-=k;
                    cout<<k<<" "<<a<<" 0 0";
                    a=0;
                }
                else cout<<"nemoguce";
            }

            if(s=="B")
            {
                if(b>=k)
                {
                    b-=k;
                    cout<<"0 0 "<<b<<" 0";
                }
                else if(b+o>=k)
                {
                    k-=b;
                    o-=k;
                    cout<<k<<" 0 "<<b<<"0";
                    b=0;
                }
                else cout<<"nemoguce";
            }
        }
        else if(s=="AB")
        {
            if(ab>=k)
            {
                ab-=k;
                cout<<"0 0 0 "<<k;
            }
            else if(k>ab+a)
            {
                k-=a;
                ab-=k;
                cout<<"0 "<<a<<" 0 "<<<k;
                a=0;
            }
            else if(k>ab+b)
            {
                k-=b;
                ab-=k;
                cout<<"0 0 "<<b<<k;
                b=0;
            }
            else if(k>ab+o)
            {
                k-=o;
                ab-=k;
                cout<<o<<" 0 0 "<<k;
                o=0;
            }
            else if(k>ab+a+b)
            {
                k-=a;
                ab-=k;
                cout<<a<<" 0 0 "<<k;
                a=0;
            }
        }
    }
    return 0;
}