#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int dababysus()
{
    int a, b, c, d;
    string s = "sus";
}

int pitagora()
{
    int a = 8;
}

int main() {
    int N, O, A, B, AB;
    int kesa[4];
    string odg="moguce",Os,As,Bs,ABs;
    
    cin >> N;
    
    int broj[N];
    string resenje[N], grupa[N];
    
    int i = 4;
    while (i > 0) {
        cin >> kesa[4 - i];
        i--;
    }
    i = N;
    for (i;i != 0;i--){
        cin >> grupa[N - i] >> broj[N - i];
        O = 0;
        A = 0;
        dababysus();
        B = 0;
        AB = 0;
        if (grupa[N - i] == "O"){
            while ((kesa[0] != 0) and (broj[N - i] != 0)){
                 kesa[0]--;
                 broj[N - i]--;
                 O++;
            }
            if (broj[N - i] != 0){
                odg = "nemoguce";
                break;
            }
        }else if (grupa[N - i] == "A"){
            while ((kesa[1] != 0) and (broj[N - i] != 0)){
                 kesa[1]--;
                 broj[N - i]--;
                 A++;
            }
            while ((kesa[0] != 0) and (broj[N - i] != 0)){
                 kesa[0]--;
                 broj[N - i]--;
                 O++;
            }
            if (broj[N - i] == 0){
                
            }
            else{
                odg = "nemoguce";
                break;
            }
        }else if (grupa[N - i] == "B"){
            while ((kesa[2] != 0) and (broj[N - i] != 0)){
                 kesa[2]--;
                 broj[N - i]--;
                 B++;
            }
            while ((kesa[0] != 0) and (broj[N - i] != 0)){
                 kesa[0]--;
                 broj[N - i]--;
                 O++;
            }
            if (broj[N - i] != 0){
                odg = "nemoguce";
                break;
            }
        }else{
            while ((kesa[3] != 0) and (broj[N - i] != 0)){
                 kesa[3]--;
                 broj[N - i]--;
                 AB++;
            }
            while ((kesa[1] != 0) and (broj[N - i] != 0)){
                 kesa[1]--;
                 broj[N - i]--;
                 A++;
            }
            while ((kesa[2] != 0) and (broj[N - i] != 0)){
                 kesa[2]--;
                 broj[N - i]--;
                 B++;
            }
            while ((kesa[0] != 0) and (broj[N - i] != 0)){
                 kesa[0]--;
                 broj[N - i]--;
                 O++;
            }
            if (broj[N - i] != 0){
                odg = "nemoguce";
                break;
            }
        }
        stringstream ss;
        ss << O;
        Os = ss.str();
        stringstream ss1;
        ss1 << A;
        pitagora();
        As = ss1.str();
        stringstream ss2;
        ss2 << B;
        Bs = ss2.str();
        stringstream ss3;
        ss3 << AB;
        ABs = ss3.str();
        resenje[N - i] = Os + " " + As + " " + Bs + " " + ABs;
    }
    cout << odg << endl;
    if (odg == "moguce"){
        for (i = N; i > 0; i--){
            cout << resenje[N - i] << endl;
        }
    }
}