#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, b, ab, o;
    int aw, bw, abw, ow;
    aw = 0;
    bw = 0;
    abw = 0;
    ow = 0;
    cin >> n;
    cin >> o >> a >> b >> ab;
    pair <string, int> arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i].first >> arr[i].second;
        if(arr[i].first == "A")
        {
            aw += arr[i].second;
        }
        else if(arr[i].first == "B")
        {
            bw += arr[i].second;
        }
        else if(arr[i].first == "AB")
        {
            abw += arr[i].second;
        }
        else
        {
            ow += arr[i].second;
        }
    }
    if(ow > o)
    {
        cout << "nemoguce";
    }
    else
    {
        int ore = o - ow;
        int ate = a;
        int bte = b;
        if(aw > (a + ore))
        {
            cout << "nemoguce";
        }
        else
        {
            if(a >= aw)
            {
                ate -= aw;
            }
            else
            {
                ore -= (aw - a);
            }
            if(bw > (b + ore))
            {
                cout << "nemoguce";
            }
            else
            {
                if(b >= bw)
                {
                    bte -= bw;
                }
                else
                {
                    ore -= (aw - a);
                }
                if(abw > (ab + ore + a + b))
                {
                    cout << "nemoguce";
                }
                else
                {
                    cout << "moguce" << endl;
                    for(int i = 0; i < n; i++)
                    {
                        if(arr[i].first == "O")
                        {
                            cout << arr[i].second << " 0 0 0" << endl;
                            o -= arr[i].second;
                        }
                        else if(arr[i].first == "A")
                        {
                            if(a > arr[i].second)
                            {
                                cout << "0 " << arr[i].second << " 0 0" << endl;
                                a -= arr[i].second;
                            }
                            else
                            {
                                cout << arr[i].second - a << " " << a << " 0 0" << endl;
                                a = 0;
                                o -= arr[i].second - a;
                            }
                        }
                        else if(arr[i].first == "B")
                        {
                            if(b > arr[i].second)
                            {
                                cout << "0 0 " << arr[i].second << " 0" << endl;
                                b -= arr[i].second;
                            }
                            else
                            {
                                cout << arr[i].second - b << " 0 " << b << " 0" << endl;
                                b = 0;
                                o -= arr[i].second;
                            }
                        }
                        else
                        {
                            if(ab >= arr[i].second)
                            {
                                cout << "0 0 0 " << arr[i].second << endl;
                                ab -= arr[i].second;
                            }
                            else if(ab + o >= arr[i].second)
                            {
                                cout << arr[i].second - ab << " 0 0 " << ab << endl;
                                ab = 0;
                                o -= arr[i].second - ab;
                            }

                            else if(ab + a >= arr[i].second)
                            {
                                cout << "0 " << arr[i].second - ab << " 0 " << ab << endl;
                                ab = 0;
                                a -= arr[i].second - ab;
                            }
                            else if(ab + b >= arr[i].second)
                            {
                                cout << "0 0 " << arr[i].second - ab << " " << ab << endl;
                                ab = 0;
                                b -= arr[i].second - ab;
                            }
                            else if(ab + o + a >= arr[i].second)
                            {
                                cout << o << " " << arr[i].second - o - ab << " 0 " << ab << endl;
                                o = 0;
                                a -= (arr[i].second - o - ab);
                                ab = 0;
                            }
                            else if(ab + o + b >= arr[i].second)
                            {
                                cout << o << " 0 " << arr[i].second - o - ab << " " << ab << endl;
                                o = 0;
                                b -= (arr[i].second - o - ab);
                                ab = 0;
                            }
                            else if(ab + a + b >= arr[i].second)
                            {
                                cout << "0 " << a << " " << arr[i].second - a - ab << " " << ab << endl;
                                a = 0;
                                b -= (arr[i].second - a - ab);
                                ab = 0;
                            }
                            else
                            {
                                cout << o << " " << a << " " << arr[i].second - o - a << " " << ab << endl;
                                o = 0;
                                a = 0;
                                b -= arr[i].second - o - a;
                                ab = 0;
                            }
                        }
                    }
                }
            }
        }
    }
}