#include <bits/stdc++.h>
#define en '\n'
#define fi first
#define se second


using namespace std;

struct pac{
    int o,a,b,ab;
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n; cin >> n;
    int O,A,B,AB; cin >> O >> A >> B >> AB;
    /// o, a, b ,ab
    /// O prima samo O
    /// A prima A i O
    /// B prima B i O
    /// AB prima sve
    vector<pair<string,int>> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i].fi >> a[i].se;
    }

    vector<pac> ans(n);
    for(int i = 0; i < n; i++){
        ans[i].o=ans[i].a=ans[i].b=ans[i].ab=0;
    }

    for(int i = 0; i < n; i++)
    {
        if(a[i].fi == "O")
        {
            ans[i].o=a[i].se;
            O -= a[i].se;
            if(O < 0) {
                cout << "nemoguce" << en;
                return 0;
            }
        }
    }

    for(int i = 0; i < n; i++)
    {
        if(a[i].fi == "A")
        {
            if(A >= a[i].se)
            {
                A -= a[i].se;
                ans[i].a = a[i].se;
            }
            else{
                ans[i].a=A;
                a[i].se -= A;
                A = 0;
                O -= a[i].se;
                ans[i].o=a[i].se;
                if(O<0){
                    cout << "nemoguce" << en;
                    return 0;
                }

            }
        }
        if(a[i].fi == "B")
        {
            if(B >= a[i].se)
            {
                B -= a[i].se;
                ans[i].b = a[i].se;
            }
            else{
                ans[i].b=B;
                a[i].se -= B;
                B = 0;
                O -= a[i].se;
                ans[i].o = a[i].se;
                if(O<0)
                {
                    cout << "nemoguce" << en;
                    return 0;
                }
            }
        }
    }

    for(int i = 0; i < n; i++)
    {
        if(a[i].fi == "AB")
        {
            if(a[i].se > 0 && O >= a[i].se)
            {
                O -= a[i].se;

                ans[i].o = a[i].se;a[i].se=0;
            }
            else if(a[i].se > 0){
                ans[i].o = O;
                a[i].se -= O;
            }

            if(a[i].se > 0 && A >= a[i].se)
            {
                A -= a[i].se;

                ans[i].a = a[i].se;a[i].se=0;
            }
            else if(a[i].se > 0){
                ans[i].a = A;
                a[i].se -= A;
            }

            if(a[i].se > 0 && B >= a[i].se)
            {
                B -= a[i].se;
                ans[i].b = a[i].se;a[i].se=0;
            }
            else if(a[i].se > 0){
                ans[i].b = B;
                a[i].se -= B;
            }

            if(a[i].se > 0 && AB >= a[i].se)
            {
                AB -= a[i].se;
                ans[i].ab = a[i].se;a[i].se=0;
            }
            else if(a[i].se > 0){
                ans[i].ab = AB;
                a[i].se -= AB;
            }

            if(a[i].se > 0)
            {
                cout << "nemoguce" << en;
                return 0;
            }


        }
    }
    cout << "moguce" << en;
    for(int i = 0; i < n; i++)
    {
        cout << ans[i].o << " " << ans[i].a << " " << ans[i].b << " " << ans[i].ab << en;
    }


}