#include <bits/stdc++.h>

using namespace std;

void solve()
{
    int n;
    int O, A, B, AB;
    cin >> n;
    cin >> O >> A >> B >> AB;
    vector<pair<string, int> > patients;
    int Or, Ar, Br, ABr;
    Or = 0;
    Ar = 0;
    Br = 0;
    ABr = 0;
    for (int i = 0; i < n; i++)
    {
        string s;
        int broj;
        cin >> s;
        cin >> broj;
        pair<string, int> p;
        p.first = s;
        p.second = broj;
        patients.push_back(p);
        if (patients[i].first == "O")
        {
            Or += broj;
        }
        if (patients[i].first == "A")
        {
            Ar += broj;
        }
        if (patients[i].first == "B")
        {
            Br += broj;
        }
        if (patients[i].first == "AB")
        {
            ABr += broj;
        }
    }
    if ((Or > O) || (Ar > (A + O - Or)) || (Br > (B + O - Or)) || ((Ar + Br) > (A + B + O - Or)) || (ABr > (O + A + AB + B - Or - Ar - Br)))
    {
        cout << "nemoguce";
        return;
    }
    cout << "moguce" << endl;
    int Oe = 0;
    int Ae = 0;
    int Be = 0;
    if (O > Or)
        Oe = O - Or;
    if (A > Ar)
        Ae = A - Ar;
    if (B > Br)
        Be = B - Br;
    for (int i = 0; i < n; i++)
    {
        if (patients[i].first == "O")
        {
            cout << patients[i].second << " " << 0 << " " << 0 << " " << 0 << endl;
        }
        if (patients[i].first == "A")
        {
            if (A >= patients[i].second)
            {
                cout << 0 << " " << patients[i].second << " " << 0 << " " << 0 << endl;
                A -= patients[i].second;
            }
            else
            {
                cout << patients[i].second - A << " " << A << " " << 0 << " " << 0 << endl;
                Oe = Oe - patients[i].second + A;
                A = 0;
            }
        }
        if (patients[i].first == "B")
        {
            if (B >= patients[i].second)
            {
                cout << 0 << " " << 0 << " " << patients[i].second << " " << 0 << endl;
                B -= patients[i].second;
            }
            else
            {
                cout << patients[i].second - B << " " << 0 << " " << B << " " << 0 << endl;
                Oe = Oe - patients[i].second + B;
                B = 0;
            }
        }
        if (patients[i].first == "AB")
        {
            if (AB >= patients[i].second)
            {
                cout << 0 << " " << 0 << " " << 0 << " " << patients[i].second << endl;
                AB -= patients[i].second;
            }
            else if (Ae >= patients[i].second - AB)
            {
                cout << 0 << " " << patients[i].second - AB << " " << 0 << " " << AB << endl;
                Ae = Ae - patients[i].second + AB;
                A = 0;
            }
            else if (Be >= patients[i].second - AB - Ae)
            {
                cout << 0 << " " << Ae << " " << patients[i].second - AB - Ae << " " << AB << endl;
                Be = Be - patients[i].second + AB + Ae;
                Ae = 0;
                AB = 0;
            }
            else
            {
                cout << patients[i].second - AB - Ae - Be << " " << Ae << " " << Be << " " << AB << endl;
                Oe = Oe - patients[i].second + AB + Ae + Be;
                Ae = 0;
                Be = 0;
                AB = 0;
            }
        }
    }
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}