#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;
        for (i; i < n; i++)
        {
            if (str[i] == "O") {
                cout << zal[i] << " " << 0 << " " << 0 << " " << 0 << endl;
            }
            else if (str[i] == "A" && o - zal[i] >= 0) {
                cout << zal[i] << " " << 0 << " " << 0 << " " << 0 << endl;
                o -= zal[i];
            }
            else if (str[i] == "A" && o - zal[i] < 0 && a >= zal[i] - o)
            {
                cout << o << " " << zal[i] - o << " " << 0 << " " << 0 << endl;
                o = 0;
                a -= zal[i] - o;
            }
            else if (str[i] == "B" && o - zal[i] >= 0)
            {
                cout << zal[i] << " " << 0 << " " << 0 << " " << 0 << endl;
                o -= zal[i];
            }
            else if (str[i] == "B" && o - zal[i] < 0 && b >= zal[i] - o)
            {
                cout << o << " " << 0 << " " << zal[i] - o << " " << 0 << endl;
                o = 0;
                b -= zal[i] - o;
            }
         }
    }
    return 0;
}