#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#define ll long long

using namespace::std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin >> n;
    ll k[4]; cin >> k[0] >> k[1] >> k[2] >> k[3];
    vector<pair<int, ll>> v;
    for (int i = 0; i < n; i++)
    {
        string c; ll x; cin >> c >> x;
        if(c == "O") v.push_back({0, x});
        else if(c == "A") v.push_back({1, x});
        else if(c == "B") v.push_back({2, x});
        else v.push_back({3, x});
    }
    bool isTrue = true;
    vector<vector<ll>> ans(n, vector<ll>(4, 0));
    for(int i=0;i<n;i++){
        if(v[i].first == 0){
            if(v[i].second <= k[0]){
                k[0] -= v[i].second;
                ans[i][0] = v[i].second;
            }
            else{
                isTrue = false;
                break;
            }
        }
    }
    if(!isTrue) {
        cout << "nemoguce" << endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        if(v[i].first == 1 || v[i].first == 2){
            if(v[i].second <= k[0] + k[v[i].first]){
                ll pom = min(k[v[i].first], v[i].second);
                k[v[i].first] -= pom;
                k[0] -= (v[i].second - pom);
                ans[i][v[i].first] = pom;
                ans[i][0] = v[i].second - pom;
            }
            else{
                isTrue = false;
                break;
            }
        }
    }
    if(!isTrue) {
        cout << "nemoguce" << endl;
        return 0;
    }
    ll p1, p2, p3, p4;
    for(int i=0;i<n;i++){
        if(v[i].first == 3){
            if(v[i].second <= k[0] + k[1] + k[2] + k[3]){
                p1 = min(k[3], v[i].second);
                k[3] -= p1; v[i].second -= p1;
                p2 = min(k[2], v[i].second);
                k[2] -= p2; v[i].second -= p2;
                p3 = min(k[1], v[i].second);
                k[1] -= p3; v[i].second -= p3;
                p4 = min(k[0], v[i].second);
                k[0] -= p4; v[i].second -= p4;
                ans[i][0] = p4; ans[i][1] = p3; ans[i][2] = p2; ans[i][3] = p1;
            }
            else{
                isTrue = false;
                break;
            }
        }
    }
    if(!isTrue) {
        cout << "nemoguce" << endl;
        return 0;
    }
    else{
        cout << "moguce" << endl;
        for(int i=0;i<n;i++){
            cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " " << ans[i][3] << endl;
        }
    }
    return 0;
}