#include <iostream>
#include <vector>
#include <numeric>
#include <sstream>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <climits>
#define watch(x) cout<<(#x)<<" is: "<<(x)<<endl
using namespace std;
typedef long long ll;


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, A, B, AB, O, Ap, Bp, ABp, Op;
	Op = 0; Ap = 0; Bp = 0; ABp = 0;
	cin>>n>>O>>A>>B>>AB;
	vector<string> fs;
	vector<int> vr;
	for(int i = 0; i < n; ++i)
    {
        string tfs; int tvr;
        cin>>tfs>>tvr;
        fs.emplace_back(tfs);
        vr.emplace_back(tvr);
        if(tfs == "O")
            Op += tvr;
        else if (tfs == "A")
            Ap += tvr;
        else if (tfs == "B")
            Bp += tvr;
        if (tfs == "AB")
            ABp += tvr;
    }


    //moguce?
    bool m = true;
    int sA = 0;
    int sB = 0;
    int sO = 0;
    if(Op <= O)
    {
        sO = O - Op;
        if(Ap<=A+sO)
        {
            if(A - Ap > 0)
                sA = A - Ap;
            else
                sO = sO + A - Ap;
            if(Bp<=B + sO)
            {
                if(B - Bp > 0)
                    sB = B - Bp;
                else
                    sO = sO + B - Bp;
                if(ABp <= AB + sA + sB + sO)
                    m = true;
                else
                    m = false;
            }
            else
                m = false;
        }
        else
            m = false;
    }
    else
        m = false;

    if(m == false)
    {
        cout<<"nemoguce";
    }
    else     //resenje
    {
        cout<<"moguce"<<"\n";
            for(int i = 0; i < n; ++i)
        {
            int a = 0; int b = 0; int ab = 0; int o = 0;
            if(fs[i] == "O")
            {
                o = vr[i];
                O -= o;
                cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
            }
            else if(fs[i] == "A")
            {
                //watch(vr[i]); watch(A); watch(a); watch(o);
                if(vr[i] < A)
                    a = vr[i];
                else
                {
                    a = A;
                    o = vr[i] - A;
                    //watch(a); watch(o);
                }
                A -= a;
                O -= o;
                //watch(a); watch(o);
                cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
            }
            else if(fs[i] == "B")
            {
                if(vr[i] < B)
                    b = vr[i];
                else
                {
                    b = B;
                    o = vr[i] - B;
                }
                B -= b;
                O -= o;
                cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
            }
            else
            {
                if(vr[i] > AB)
                {
                    vr[i] -= AB;
                    ab = AB;
                    AB = 0;
                    if(A - Ap > B - Bp)
                    {
                        if(vr[i] > A)
                        {
                            vr[i] -= A;
                            a = A;
                            A = 0;
                            if(vr[i] > B)
                            {
                                vr[i] -= B;
                                b = B;
                                B = 0;
                                o = vr[i];
                                O -= o;
                                cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
                            }
                            else
                            {
                                b = vr[i];
                                B -= b;
                                cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
                            }
                        }
                        else
                        {
                            a = vr[i];
                            A -= a;
                            cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
                        }
                    }
                    else
                    {
                        if(vr[i] > B)
                        {
                            vr[i] -= B;
                            b = B;
                            B = 0;
                            if(vr[i] > A)
                            {
                                vr[i] -= A;
                                b = A;
                                A = 0;
                                o = vr[i];
                                O -= o;
                                cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
                            }
                            else
                            {
                                a = vr[i];
                                A -= a;
                                cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
                            }
                        }
                        else
                        {
                            b = vr[i];
                            B -= b;
                            cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
                        }
                    }
                }
                else
                {
                    ab = vr[i];
                    AB -= ab;
                    cout<<o<<" "<<a<<" "<<b<<" "<<ab<<"\n";
                }
            }

        }
    }

}