#include <iostream>
#include <string>

using namespace std;

int main(){
    int n, o, a, b, ab;
    cin >> n >> o >> a >> b >> ab;

    int matrix[n][4] = {};
    int arr[n] = {};
    bool supply = true;


    // resiti
    for(int i = 0; i < n; i++){
        string s;
        int k;
        cin >> s >> k;

        if(s == "AB"){
            arr[i] = k;
        }else if(s == "A"){
            if(k <= a){
                matrix[i][0] = 0;
                matrix[i][1] = k;
                matrix[i][2] = 0;
                matrix[i][3] = 0;
                
                a -= k;
            }else{
                matrix[i][1] = a;
                k -= a;
                a = 0;

                if(k <= o){
                    matrix[i][0] = k;
                    matrix[i][2] = 0;
                    matrix[i][3] = 0;

                    o -= k;
                }else{
                    supply = false;
                    break;
                }
            }
        }else if(s == "B"){
            if(k <= b){
                matrix[i][0] = 0;
                matrix[i][1] = k;
                matrix[i][2] = 0;
                matrix[i][3] = 0;

                b -= k;
            }else{
                matrix[i][1] = b;
                k -= b;
                b = 0;

                if(k <= o){
                    matrix[i][0] = k;
                    matrix[i][2] = 0;
                    matrix[i][3] = 0;

                    o -= k;
                }else{
                    supply = false;
                    break;
                }
            }
        }else{
            if(k <= o){
                matrix[i][0] = k;
                matrix[i][1] = 0;
                matrix[i][2] = 0;
                matrix[i][3] = 0;

                o -= k;
            }else{
                supply = false;
                break;
            }
        }
    }

    if(supply){
        for(int i = 0; i < n; i++){
            if(arr[i]){
                int r = arr[i];

                if(r <= o){
                    matrix[i][0] = r;
                    matrix[i][1] = 0;
                    matrix[i][2] = 0;
                    matrix[i][3] = 0;

                    o -= r;
                }else{
                    r -= o;
                    matrix[i][0] = o;
                    o = 0;

                    if(r <= a){
                        matrix[i][1] = r;
                        matrix[i][2] = 0;
                        matrix[i][3] = 0;

                        a -= r;
                    }else{
                        matrix[i][1] = a;
                        r -= a;
                        a = 0;

                        if(r <= b){
                            matrix[i][2] = r;
                            matrix[i][3] = 0;

                            b -= r;
                        }else{
                            matrix[i][2] = b;
                            r -= b;
                            b = 0;

                            if(r <= ab){
                                matrix[i][3] = r;
                                ab -= r;
                            }else{
                                supply = false;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

    // resenje
    if(supply){
        cout << "moguce";
        cout << endl;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 4; j++){
                cout << matrix[i][j] << " ";
            }
            cout << endl;
        }
    }else{
        cout << "nemoguce";
    }
}