#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;

    map<string, vec<pair<ll, int>>> a;
    string in1;
    ll in2;
    for(int i = 0; i < n; ++i){
        cin >> in1 >> in2;
        a[in1].pb({in2, i});
    }

    vec<string> symols = {"O", "A", "B", "AB"};

    long long sum_O = 0, sum_A = 0, sum_B = 0, sum_AB = 0;

    for(auto S : symols){
        for(auto &x : a[S]){
            if(S == "O")
                sum_O += x.fi;
            else if(S == "A")
                sum_A += x.fi;
            else if(S == "B")
                sum_B += x.fi;
            else 
                sum_AB += x.fi;
        }
    }

    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;
    };

    long long take_O = 0, take_A = 0, take_B = 0, take_AB = 0;

    vec<array<long long, 4>> ans(n);

    fun<void()> reset = [&] (){
        take_O = 0;
        take_A = 0;
        take_B = 0;
        take_AB = 0;
    };

    fun<void(int)> addToAns = [&] (int index){
        ans[index] = {{take_O, take_A, take_B, take_AB}};
    };

    if(test()){
        cout << "moguce" << ends;
    
        for(auto &x : a["O"]){
            reset();

            take_O = x.fi;
            O -= x.fi;

            addToAns(x.se);
        }

        for(auto &x : a["A"]){
            reset();

            if(x.fi > A){
                take_A = A;
                take_O = (x.fi - A);

                O -= (x.fi - A);
                A = 0;
            }else{
                take_A = x.fi;
                A -= x.fi;
            }

            addToAns(x.se);
        }

        for(auto &x : a["B"]){
            reset();

            if(x.fi > B){
                take_B = B;
                take_O = (x.fi - B);

                O -= (x.fi - B);
                B = 0;
            }else{
                take_B = x.fi;
                B -= x.fi;
            }

            addToAns(x.se);
        }

        for(auto &x : a["AB"]){
            reset();

            long long take = x.fi;
            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;

            addToAns(x.se);
        }



        for(auto x : ans){
            cout << x[0] << sp << x[1] << sp << x[2] << sp << x[3] << ends;
        }

    }else
        cout << "nemoguce" << ends;
    
 	
}