#include <iostream>
#include <string>
using namespace std;

void transfer(int &primalacX, int &donorX, int &brX){
   if(primalacX > donorX){
       primalacX = primalacX - donorX;
       brX = donorX;
       donorX = 0;
   }
   else {
       donorX = donorX - primalacX;
       brX = primalacX;
       primalacX = 0;
   }
    
}

int provera (int primalacO,int primalacA,int primalacB,int primalacAB){
    if (primalacA != 0)
        return 1;
    if (primalacB != 0)
        return 1;
    if (primalacAB != 0)
        return 1;
    if (primalacO != 0)
        return 1;
        
    return 0;
}

int main(){
    int N;
    string ulazSTRING;
    int ulazINT;
    int donorO, donorA, donorB, donorAB, primalacO, primalacA, primalacB, primalacAB;
    short ispisO = 0, ispisA = 0, ispisB = 0, ispisAB = 0;
    //                 0  A  B  AB
    //                [0][1][2][3]
    int brojacO[4]  = {0, 0, 0, 0};
    int brojacA[4]  = {0, 0, 0, 0};
    int brojacB[4]  = {0, 0, 0, 0};
    int brojacAB[4] = {0, 0, 0, 0};
    donorO = donorA = donorB = donorAB = primalacO = primalacA = primalacB = primalacAB = 0;
    string A ("A");
    string B ("B");
    string AB ("AB");
    string O = ("O");
    cin >> N;
    cin >> donorO >> donorA >> donorB >> donorAB;
    for (int i = 0; i < N; i++){
        cin >> ulazSTRING >> ulazINT;
        if (A.compare(ulazSTRING) == 0){
            primalacA = ulazINT;
            ispisA = 1;
        }
        if (B.compare(ulazSTRING) == 0){
            primalacB = ulazINT;
            ispisB = 1;
        }
        if (O.compare(ulazSTRING) == 0){
            primalacO = ulazINT;
            ispisO = 1;
        }
        if (AB.compare(ulazSTRING) == 0){
            primalacAB = ulazINT;
            ispisAB = 1;
        }
    }
    transfer(primalacAB, donorAB, brojacAB[3]);
    transfer(primalacO, donorO, brojacO[0]);
    transfer(primalacA, donorA, brojacA[1]);
    transfer(primalacB, donorB, brojacB[2]);
    transfer(primalacAB, donorA, brojacAB[1]);
    transfer(primalacAB, donorB, brojacAB[2]);
    transfer(primalacA, donorO, brojacA[0]);
    transfer(primalacB, donorO, brojacB[0]);
    transfer(primalacAB, donorO, brojacAB[0]);
    
    if (provera(primalacO, primalacA, primalacB, primalacAB))
        cout << "nemoguce";
    else{
        cout << "moguce";
        if (ispisO)
            for (int i = 0; i < 4; i++)
                cout << brojacO[i] << " ";
            cout << endl;
        if (ispisA)
            for (int i = 0; i < 4; i++)
                cout << brojacA[i] << " ";
            cout << endl;
        if (ispisB)
            for (int i = 0; i < 4; i++)
                cout << brojacB[i] << " ";
            cout << endl;
        if (ispisAB)
            for (int i = 0; i < 4; i++)
                cout << brojacAB[i] << " ";
            cout << endl;
    }

    
    
    

    return 0;
}