#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long long> zalihe(4);
    vector<pair<string, long long>> krv(n);
    vector<vector<long long>> ispis(n);
    for (long long i = 0; i < n; i++)
        ispis[i].resize(4);
    for (int i = 0; i < 4; i++)
        cin >> zalihe[i];
    for (int i = 0; i < n; i++){
        string str; long long br;
        cin >> str >> br;
        krv[i].first = str;
        krv[i].second = br;
    }
    for (long long i = 0; i < n; i++){
        if (krv[i].first == "O"){
            zalihe[0] -= krv[i].second;
            ispis[i][0] += krv[i].second;
            if (zalihe[0] < 0){
                cout << "nemoguce" << endl;
                return 0;
            }
        }
    }
    for (long long i = 0; i < n; i++){
        if (krv[i].first == "A"){
            if (zalihe[1] - krv[i].second >= 0){
                zalihe[1] -= krv[i].second;
                ispis[i][1] += krv[i].second;
            }
            else{
                krv[i].second -= zalihe[1];
                ispis[i][1] += zalihe[1];
                zalihe[1] = 0;
                zalihe[0] -= krv[i].second;
                ispis[i][0] += krv[i].second;
            }
            if (zalihe[0] < 0){
                cout << "nemoguce" << endl;
                return 0;
            }
        }
    }
    for (long long i = 0; i < n; i++){
        if (krv[i].first == "B"){
            if (zalihe[2] - krv[i].second >= 0){
                zalihe[2] -= krv[i].second;
                ispis[i][2] += krv[i].second;
            }
            else{
                krv[i].second -= zalihe[2];
                ispis[i][2] += zalihe[2];
                zalihe[2] = 0;
                zalihe[0] -= krv[i].second;
                ispis[i][0] += krv[i].second;
            }
            if (zalihe[0] < 0){
                cout << "nemoguce" << endl;
                return 0;
            }
        }
    }
    for (long long i = 0; i < n; i++){
        if (krv[i].first == "AB"){
            if (zalihe[3] - krv[i].second >= 0){
                zalihe[3] -= krv[i].second;
                ispis[i][3] += krv[i].second;
                break;
            }
            else{
                krv[i].second -= zalihe[3];
                ispis[i][3] += zalihe[3];
                zalihe[3] = 0;
            }
            if (zalihe[2] - krv[i].second >= 0){
                zalihe[2] -= krv[i].second;
                ispis[i][2] += krv[i].second;
                break;
            }
            else{
                krv[i].second -= zalihe[2];
                ispis[i][2] += zalihe[2];
                zalihe[2] = 0;
            }
            if (zalihe[1] - krv[i].second >= 0){
                zalihe[1] -= krv[i].second;
                ispis[i][1] += krv[i].second;
                break;
            }
            else{
                krv[i].second -= zalihe[1];
                ispis[i][1] += zalihe[1];
                zalihe[1] = 0;
            }
            zalihe[0] -= krv[i].second;
            ispis[i][0] += krv[i].second;
            if (zalihe[0] < 0){
                cout << "nemoguce" << endl;
                return 0;
            }
        }
    }

    cout << "moguce" << endl;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 4; j++)
            cout << ispis[i][j] << " ";
        cout << endl;
    }
	return 0;
}