#import <iostream>
#import <string>
#import <cmath>
using namespace std;

int main(){
    int N, O, A, B, AB;
    cin >> N >> O >> A >> B >> AB;
    int mat[N][4] = {0};
    int nizAB[N] = {0};
    int t = 1;
    for(int i = 0; i < N; i++){
        string grupa;
        int val;
        cin >> grupa;
        cin >> val;
        if(grupa == "O"){
            if(val > O){
                cout << "nemoguce";
                t = 0;
                break;
            }else{
                O -= val;
                mat[i][0] = val;
            }
        }else if(grupa == "A"){
            if(val > A){
                val -= A;
                mat[i][1] = A;
                A = 0;
                if(val > O){
                    cout << "nemoguce";
                    t = 0;
                    break;
                }else{
                    O -= val;
                    mat[i][0] = val;
                }
            }else{
                A -= val;
                mat[i][1] = val;
            }
        }else if(grupa == "B"){
            if(val > B){
                val -= B;
                mat[i][2] = B;
                B = 0;
                if(val > O){
                    cout << "nemoguce";
                    t = 0;
                    break;
                }else{
                    O -= val;
                    mat[i][0] = val;
                }
            }else{
                B -= val;
                mat[i][2] = val;
            }
        }else{
            nizAB[i] = val;
        }
    }
    
    if(t == 1){
        for(int i = 0; i < N; i++){
            int val = nizAB[i];
            if(val > AB){
                val -= AB;
                mat[i][3] = AB;
                AB = 0;
                if(val > B){
                    val -= B;
                    mat[i][2] = B;
                    B = 0;
                    if(val > A){
                        val -= A;
                        mat[i][1] = A;
                        A = 0;
                        if(val > O){
                            t = 0;
                            cout << "nemoguce";
                            break;
                        }else{
                            O -= val;
                            mat[i][0] = val;
                        }
                    }else{
                        A -= val;
                        mat[i][1] = val;
                    }
                }else{
                    B -= val;
                    mat[i][2] = val;
                }
            }else{
                AB -= val;
                mat[i][3] = val;
            }
        }
    }
    if(t == 1){
        cout << "moguce" << endl;
        for(int i = 0; i < N; i++){
            for(int j = 0; j < 4; j++){
                cout << mat[i][j] << " ";
            }
            cout << endl;
        }
    }
}