#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4+34;

int n,O,A,B,AB;
int res[N][4];
int sta[N],br[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    cin >> O >> A >> B >> AB;
    for(int i = 1; i <= n; i++){
        string s;
        cin >> s >> br[i];

        if(s == "O") sta[i] = 0;
        else if(s == "A") sta[i] = 1;
        else if(s == "B") sta[i] = 2;
        else sta[i] = 3;
    }

    for(int i = 1; i <= n; i++){
        if(sta[i] == 0){
            if(O < br[i]){
                cout << "nemoguce" << endl;
                return 0;
            }
            res[i][0] += br[i];
            O -= br[i];
            br[i] = 0;
        }
        if(sta[i] == 1){
            int daj = min(br[i],A);
            res[i][1] += daj;
            A -= daj;
            br[i] -= daj;
        }
        if(sta[i] == 2){
            int daj = min(br[i],B);
            res[i][2] += daj;
            B -= daj;
            br[i] -= daj;
        }
    }

    for(int i = 1; i <= n; i++){
        if(sta[i] == 1 && br[i]){
            assert(A == 0);
            if(O < br[i]){
                cout << "nemoguce" << endl;
                return 0;
            }
            res[i][0] += br[i];
            O -= br[i];
            br[i] = 0;
        }
        if(sta[i] == 2 && br[i]){
            assert(B == 0);
            if(O < br[i]){
                cout << "nemoguce" << endl;
                return 0;
            }
            res[i][0] += br[i];
            O -= br[i];
            br[i] = 0;
        }
    }

    for(int i = 1; i <= n; i++){
        if(sta[i] == 3 && br[i]){
            int daj = min(O,br[i]);
            res[i][0] += daj;
            O -= daj;
            br[i] -= daj;
        }
    }
    for(int i = 1; i <= n; i++){
        if(sta[i] == 3 && br[i]){
            int daj = min(A,br[i]);
            res[i][1] += daj;
            A -= daj;
            br[i] -= daj;
        }
    }
    for(int i = 1; i <= n; i++){
        if(sta[i] == 3 && br[i]){
            int daj = min(B,br[i]);
            res[i][2] += daj;
            B -= daj;
            br[i] -= daj;
        }
    }
    for(int i = 1; i <= n; i++){
        if(sta[i] == 3 && br[i]){
            int daj = min(AB,br[i]);
            res[i][3] += daj;
            AB -= daj;
            br[i] -= daj;
        }
    }

    for(int i = 1; i <= n; i++){
        if(br[i] != 0){
            cout << "nemoguce" << endl;
            return 0;
        }
    }

    cout << "moguce" << endl;
    for(int i = 1; i <= n; i++){
        cout << res[i][0] << " " << res[i][1] << " " << res[i][2] << " " << res[i][3] << endl;
    }
}