#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define sz(x) ((int)(x).size())
#define pb push_back
#define vec vector
#define fi first
#define se second
#define ends "\n"
#define sp ' '
#define fun function
#define ar(x) array<int, x>
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const long long MOD=1e9+7; 

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)



int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
 	
    int n;
    cin >> n;

    int O, A, B, AB;
    cin >> O >> A >> B >> AB;

    vec<pair<string, ll>> a(n);
    for(auto &x : a)
        cin >> x.fi >> x.se;

    long long sum_O = 0, sum_A = 0, sum_B = 0, sum_AB = 0;
    for(int i = 0; i < n; ++i){
        if(a[i].fi == "O")
            sum_O += a[i].se;
        else if(a[i].fi == "A")
            sum_A += a[i].se;
        else if(a[i].fi == "B")
            sum_B += a[i].se;
        else 
            sum_AB += a[i].se;
    }

    fun<bool()> test = [&]() {
        if(sum_O > O)
            return false;
        long long rest_O = O - sum_O;

        long long needMoreA = 0;
        if(sum_A > A)
            needMoreA = sum_A - A;

        long long needMoreB = 0;
        if(sum_B > B)
            needMoreB = sum_B - B;

        if(needMoreB + needMoreA > rest_O)
            return false;

        long long rest_A = max(0LL, A - sum_A);
        long long rest_B = max(0LL, B - sum_B);

        long long restrest_O = rest_O - (needMoreB + needMoreA) + rest_A + rest_B;
        if(sum_AB > AB + restrest_O)
            return false;
        return true;
    };
    bool ok = test();
    if(ok){
        cout << "moguce" << ends;

        for(int i = 0; i < n; ++i){
            long long take_O = 0, take_A = 0, take_B = 0, take_AB = 0;
            if(a[i].fi == "O"){
                take_O = a[i].se;

                O -= a[i].se;
            }else if(a[i].fi == "A"){
                if(a[i].se > A){
                    take_A = A;
                    take_O = (a[i].se - A);

                    O -= (a[i].se - A);
                    A = 0;
                }else{
                    take_A = a[i].se;
                    A -= a[i].se;
                }
            }else if(a[i].fi == "B"){
                if(a[i].se > B){
                    take_B = B;
                    take_O = (a[i].se - B);

                    O -= (a[i].se - B);
                    B = 0;
                }else{
                    take_B = a[i].se;
                    B -= a[i].se;
                }
            }else{
                long long take = a[i].se;
                if(take > AB){
                    take_AB = AB;
                    take -= AB;
                    AB = 0;
                }else{
                    take_AB = take;
                    AB -= take; 
                    take = 0;
                }

                if(take > B){
                    take_B = B;
                    take -= B;
                    B = 0;
                }else{
                    take_B = take;
                    B -= take; 
                    take = 0;
                }

                if(take > A){
                    take_A = A;
                    take -= A;
                    A = 0;
                }else{
                    take_A = take;
                    A -= take; 
                    take = 0;
                }

                take_O = take;
                O -= take;
            
            }

            cout << take_O << sp << take_A << sp << take_B << sp << take_AB << ends;
        }
    }else{
        cout << "nemoguce" << ends;
    }
 	
}