#include <iostream>
using namespace std;

int main() {

    int N, i=0, sumRequired=0, sumA=0, sumB=0, sumAB=0, sumO=0;
    int array[4];
    cin >> N >> array[0] >>  array[1] >> array[2] >> array[3];
    string type[N];
    int units[N];
    for (int j = 0; j < N; j++){
        cin >> type[j] >> units[j];
    }
    
    int sum = array[0] + array[1] + array[2] + array[3];
    for (int j = 0; j < N; j++){
        sumRequired += units[j];
        if(type[j] == "A")
            sumA += units[j];
         else if(type[j] == "B")
            sumB += units[j];
         else if (type[j] == "O")
            sumO += units[j];
         else
            sumAB += units[j];
    }
    if( sum < sumRequired || sumO > array[0] || sumA > (array[0]-sumO + array[1]) || sumB > (array[0]-sumO + array[2]) || ((array[0]-sumO + array[1]) == sumA && sumB > array[2] ) || ((array[0]-sumO + array[2]) == sumB && sumA > array[1] )) {
        cout << "nemoguce";
    }
    else {
        cout << "moguce" << endl;
        int solution[N][4];
        for(int j = 0; j < N; j++){
            for(int k = 0; k < 4; k++ ){
                solution[j][k] = 0;
            }
        }
        int leftA=array[1], leftB=array[2], leftO=array[0], leftAB=array[3]; 
        for(int j = 0; j < N; j++) {
            if(type[j] == "O"){
                solution[j][0] = units[j];
                leftO -= units[j];
                
            }
            else if(type[j] == "A"){
                if(leftA >= units[j]){
                    solution[j][1] = units[j];
                    leftA -= units[j];
                } else {
                    solution[j][1] = leftA;
                    solution[j][0] = units[j] - leftA;
                    leftO -= units[j] - leftA;
                    leftA = 0;
                }
            }
            else if(type[j] == "B"){
                if(leftB >= units[j]){
                    solution[j][2] = units[j];
                    leftB -= units[j];
                } else {
                    solution[j][2] = leftB;
                    solution[j][0] = units[j] - leftB;
                    leftO -= units[j] - leftB;
                    leftB = 0;
                }
            }
            else {
                    if(leftAB >= units[j]) {
                        solution[j][3] = units[j];
                        leftAB -= units[j];
                    } else {
                        solution[j][3] = leftAB;
                        int left = units[j] - leftAB;
                        leftAB = 0;
                        
                        if(left != 0 && array[2] - sumB >= left ) {
                            solution[j][2] = left;
                            leftB -=left;
                            left = 0;
                        }
                        else if(left != 0 && array[2] - sumB > 0){
                            solution[j][2] = array[2] - sumB;
                            leftB -= array[2] - sumB;
                            left = units[j] - solution [j][3] - solution[j][2];
                        }
                
                        if(left != 0 && array[1] - sumA >= left ) {
                            solution[j][1] = left;
                            leftA -=left;
                            left = 0;
                        }
                        else if(left != 0 && array[1] - sumA > 0){
                            solution[j][1] = array[1] - sumA;
                            leftA -= array[1] - sumA;
                            left = units[j] - solution [j][3] - solution[j][2] - solution[j][1];
                        }
                        if(left!=0) {
                            solution[j][0] = left;
                            leftO -= left;
                            left = 0;
                        }
                    }
            }
        }
        for(int j = 0; j < N; j++){
            for(int k = 0; k < 4; k++ ){
                cout << solution[j][k] << " " ;
            }
            cout << endl;
        }
    }
    
    return 0;
}