#include<bits/stdc++.h>

using namespace std;

vector<pair<string,int>> p;
vector<pair<pair<string,int>, int>> p2;
vector<pair<vector<int>, int>> ansvec;


bool sortbysec1(const pair<pair<string,int>,int> &a,
              const pair<pair<string,int>,int> &b)
{
    return (a.second < b.second);
}

bool sortbysec2(const pair<vector<int>,int> &a,
              const pair<vector<int>,int> &b)
{
    return (a.second < b.second);
}

int main() {

    //ios::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);

    int p2c = 0;

    int tmpnum;
    string tmpstr;
    int tmpmin;

    int n;
    cin >> n;
    int o, a, b, ab;
    cin >> o >> a >> b >> ab;
    for(int i=0;i<n;i++) {
        cin >> tmpstr;
        cin >> tmpnum;
        p.push_back(make_pair(tmpstr,tmpnum));
    }


    for(int i=0;i<n;i++) {
        if(!(p[i].first.compare("O"))) {
            p2.push_back(make_pair(make_pair(p[i].first, p[i].second), i));
            p2c++;
        }
    }

    for(int i=0;i<n;i++) {
        if(!(p[i].first.compare("A"))) {
            p2.push_back(make_pair(make_pair(p[i].first, p[i].second), i));
            p2c++;
        }
    }

    for(int i=0;i<n;i++) {
        if(!(p[i].first.compare("B"))) {
            p2.push_back(make_pair(make_pair(p[i].first, p[i].second), i));
            p2c++;
        }
    }

    for(int i=0;i<n;i++) {
        if(!(p[i].first.compare("AB"))) {
            p2.push_back(make_pair(make_pair(p[i].first, p[i].second), i));
            p2c++;
        }
    }

    for(int i=0;i<n;i++) {
        if(p2[i].first.first == "O") {
            if(o>=p2[i].first.second) {
                o -= p2[i].first.second;
                p2[i].first.second = 0;
                ansvec.push_back(make_pair(vector<int>(4), i));
                ansvec[i].first[0] = p2[i].first.second;
            }
            else {
                cout << "nemoguce";
                return 0;
            }
        }
        else if(p2[i].first.first == "A") {
            tmpmin = min(a,p2[i].first.second);
            a -= tmpmin;
            p2[i].first.second -= tmpmin;
            ansvec.push_back(make_pair(vector<int>(4), p2[i].second));
            ansvec[i].first[1] = tmpmin;
            tmpmin = min(o,p2[i].first.second);
            o -= tmpmin;
            p2[i].first.second -= tmpmin;
            ansvec[i].first[0] = tmpmin;
            if(p2[i].first.second > 0) {
                cout << "nemoguce";
                return 0;
            }
        }

        else if(p2[i].first.first == "B") {
            tmpmin = min(b, p2[i].first.second);
            b -= tmpmin;
            p2[i].first.second -= tmpmin;
            ansvec.push_back(make_pair(vector<int>(4), p2[i].second));
            ansvec[i].first[2] = tmpmin;
            tmpmin = min(o, p2[i].first.second);
            o -= tmpmin;
            p2[i].first.second -= tmpmin;
            ansvec[i].first[0] = tmpmin;
            if(p2[i].first.second > 0) {
                cout << "nemoguce";
                return 0;
            }
        }
        else if(p2[i].first.first == "AB") {
            tmpmin = min(ab, p2[i].first.second);
            ab -= tmpmin;
            p2[i].first.second -= tmpmin;
            ansvec.push_back(make_pair(vector<int>(4), p2[i].second));
            ansvec[i].first[3] = tmpmin;
            tmpmin = min(a, p2[i].first.second);
            a -= tmpmin;
            p2[i].first.second -= tmpmin;
            ansvec[i].first[1] = tmpmin;
            tmpmin = min(b, p2[i].first.second);
            b -= tmpmin;
            p2[i].first.second -= tmpmin;
            ansvec[i].first[2] = tmpmin;
            tmpmin = min(o, p2[i].first.second);
            o -= tmpmin;
            p2[i].first.second -= tmpmin;
            ansvec[i].first[0] = tmpmin;

            if(p2[i].first.second > 0) {
                cout << "nemoguce";
                return 0;
            }
        }
    }

    cout << "moguce\n";

    sort(ansvec.begin(), ansvec.end(), sortbysec2);
    sort(p2.begin(), p2.end(), sortbysec1);

    for(int i=0;i<n;i++) {
        cout << ansvec[i].first[0] << " " << ansvec[i].first[1] << " " << ansvec[i].first[2] << " " << ansvec[i].first[3] << "\n";
    }

    return 0;
}