#include <iostream>
#include <string>
#define MAX_N 10000
typedef unsigned int ui;
using namespace std;
int main()
{
    string str[MAX_N];
    int n, zal[MAX_N];
    cin >> n;
    int o, a, b, ab;
    cin >> o >> a >> b >> ab;
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> str[i] >> zal[i];
        if (str[i] == "O")o -= zal[i];
        else if (str[i] == "A")sum1 += zal[i];
        else if (str[i] == "B")sum2 += zal[i];
    }
    if (o < 0 || sum1 > a + o || sum2 > b + o || (sum1 - a + sum2 - b > o && sum1 > a && sum2 > b))cout << "nemoguce";
    else {
        cout << "moguce" << endl;
        int i = 0;
        int ost1 = sum1 - a, ost2 = sum2 - b;
        for (i; i < n; i++)
        {
            if (str[i] == "O") {
                cout << zal[i] << " " << 0 << " " << 0 << " " << 0 << endl;
            }
            else if (str[i] == "A") {
                if (ost1 < 0)
                {
                    cout << 0 << " " << zal[i] << " " << 0 << " " << 0 << endl;
                }
                else {
                    if (ost1 < zal[i]) {
                        cout << ost1 << " " << zal[i] - ost1 << " " << 0 << " " << 0 << endl;
                        ost1 = 0;
                    }
                    else {
                        cout << zal[i] << " " << 0 << " " << 0 << " " << 0 << endl;
                        ost1 -= zal[i];
                    }
                }
            }
            else if (str[i] == "B")
            {
                if (ost2 < 0) {
                    cout << 0 << " " << 0 << " " << zal[i] << " " << 0 << endl;
                }
                else {
                    if (ost2 < zal[i]) {
                        cout << ost2 << " " << 0 << " " << zal[i] - ost2 << " " << 0 << endl;
                        ost2 = 0;
                    }
                    else {
                        cout << zal[i] << " " << 0 << " " << 0 << " " << 0 << endl;
                        ost2 -= zal[i];
                    }
                }
            }
        }
    }
    return 0;
}