#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ll n, o, a, b, ab, po = 0, pa = 0, pb = 0, pab = 0, ro = 0, ra = 0, rb = 0, rab = 0, oa = 0, ob = 0, oab = 0, aab = 0, bab = 0;
    string grp;

    cin >> n >> o >> a >> b >> ab;

    vector<string> pgrp(n);
    vector<ll> pklk(n);

    for (ll i = 0; i < n; i++)
    {
        cin >> pgrp[i] >> pklk[i];
        if (pgrp[i] == "O")
            po += pklk[i];
        else if (pgrp[i] == "A")
            pa += pklk[i];
        else if (pgrp[i] == "B")
            pb += pklk[i];
        else if (pgrp[i] == "AB")
            pab += pklk[i];
    }

    ro = o - po;

    if (ro < 0)
    {
        cout << "nemoguce";
        return 0;
    }

    ra = a - pa;

    if (ra < 0)
    {
        if (ro >= -ra)
        {
            ro += ra;
            oa = -ra;
            ra = 0;
        }
        else
        {
            cout << "nemoguce";
            return 0;
        }
    }

    rb = b - pb;

    if (rb < 0)
    {
        if (ro >= -rb)
        {
            ro += rb;
            ob = -rb;
            rb = 0;
        }
        else
        {
            cout << "nemoguce";
            return 0;
        }
    }

    rab = ab - pab;
    if (ro > 0)
    {
        rab += ro;
        oab = ro;
    }
    if (ra > 0)
    {
        rab += ra;
        aab = ra;
    }
    if (rb > 0)
    {
        rab += rb;
        bab = rb;
    }

    if (rab < 0)
    {
        cout << "nemoguce";
        return 0;
    }

    a -= aab;
    b -= bab;

    cout << "moguce";
    for (int i = 0; i < n; i++)
    {
        cout << '\n';
        if (pgrp[i] == "O")
            cout << pklk[i] << " 0" << " 0" << " 0";
            
        else if (pgrp[i] == "A")
        {
            if (oa >= pklk[i])
            {
                cout << pklk[i] << " 0" << " 0" << " 0";
                oa -= pklk[i];
            }
            else if (a >= pklk[i])
            {
                cout << "0 " << pklk[i] << " 0" << " 0";
                a -= pklk[i];
            }
            else cout << oa << " " << a << " 0" << " 0";
        }

        else if (pgrp[i] == "B")
        {
            if (ob >= pklk[i])
            {
                cout << pklk[i] << " 0" << " 0" << " 0";
                ob -= pklk[i];
            }
            else if (b >= pklk[i])
            {
                cout << "0" << " 0 " << pklk[i] << " 0";
                b -= pklk[i];
            }
            else cout << ob << " 0 " << b << " 0";
        }

        else if (pgrp[i] == "AB")
        {
            if (ab >= pklk[i])
            {
                cout << "0" << " 0" << " 0 " << pklk[i];
                ab -= pklk[i];
            }
            else if (bab >= pklk[i])
            {
                cout << "0" << " 0 " << pklk[i] << " 0";
                bab -= pklk[i];
            }
            else if (aab >= pklk[i])
            {
                cout << "0 " << pklk[i] << " 0" << " 0";
                aab -= pklk[i];
            }
            else if (oab >= pklk[i])
            {
                cout << pklk[i] << " 0" << " 0" << " 0";
                oab -= pklk[i];
            }
            else if (oab + aab + bab + ab == pklk[i])
            {
                cout << oab << " " << aab << " " << bab << " " << ab;
                oab = 0; aab = 0; bab = 0; ab = 0;
            }
            else
            {
                cout << oab << " ";
                if (oab + aab >= pklk[i])
                {
                    cout << pklk[i] - oab << " 0" << " 0";
                    aab = aab - pklk[i] - oab;
                }
                else
                {
                    cout << aab << " ";
                    if (oab + aab + bab >= pklk[i])
                    {
                        cout << pklk[i] - oab - aab << " 0";
                        bab = bab - pklk[i] - oab - aab;
                    }
                    else if (oab + aab + ab >= pklk[i])
                    {
                        cout << "0 " << pklk[i] - oab - aab;
                        ab = ab - pklk[i] - oab - aab;
                    }
                    aab = 0;
                }
                oab = 0;
            }
        }
    }
    return 0;
}