#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    long long unsigned int p,O,A,B,AB;
    cin>>p;
    long long unsigned int jedinice[p];
    
    cin>>O>>A>>B>>AB;
    string grupe[p];
    for (auto i=0; i < p; i ++){
        cin>>grupe[i];
        cin>>jedinice[i];
    }
    long long unsigned int res[p][4];
    for (auto i =0; i < p ; i ++){
        for (auto j=0; j< 4; j ++){
            res[i][j]=0;
        }
    }
    for (auto i =0; i<p; i ++)
    {
        if (grupe[i]=="O"){
            if (O>=jedinice[i]){
                res[i][0]=jedinice[i];
                O-=jedinice[i];
                jedinice[i]=0;
            }
            else{
                cout<<"nemoguce";
                return 0;
            }
        }
    }
    for (auto i =0; i<p; i ++)
    {
        if (grupe[i]=="A"){
            
            if (A<jedinice[i]){
                jedinice[i]= jedinice[i]-A;
                res[i][1]=A;
                A=0;
            
                if (O>=jedinice[i]){
                    res[i][0]=jedinice[i];
                    O-=jedinice[i];
                    jedinice[i]=0;
                    
                }
                else{
                    cout<<"nemoguce";
                    return 0;
                }
            }
            else{
                res[i][1]=jedinice[i];
                A-=jedinice[i];
                jedinice[i]=0;
            }
            
        }
    }
    for (auto i =0; i<p; i ++)
    {
        if (grupe[i]=="B"){
            
            if (B<jedinice[i]){
                jedinice[i]= jedinice[i]-B;
                res[i][2]=B;
                B=0;
            
                if (O>=jedinice[i]){
                    res[i][0]=jedinice[i];
                    O-=jedinice[i];
                    jedinice[i]=0;
                    
                }
                else{
                    cout<<"nemoguce";
                    return 0;
                }
            }
            else{
                res[i][2]=jedinice[i];
                B-=jedinice[i];
                jedinice[i]=0;
            }
            
        }
    }
    for (auto i =0; i<p; i ++)
    {
        if (grupe[i]=="AB"){
            
            if (AB<jedinice[i]){
                jedinice[i]= jedinice[i]-AB;
                res[i][3]=AB;
                AB=0;
            }
            else{
                res[i][3]=jedinice[i];
                AB-=jedinice[i];
                jedinice[i]=0;
                continue;
            }
            if (A<jedinice[i]){
                jedinice[i]= jedinice[i]-A;
                res[i][1]=A;
                A=0;
            }
            else{
                res[i][1]=jedinice[i];
                A-=jedinice[i];
                jedinice[i]=0;
                continue;
            }
            if (B<jedinice[i]){
                jedinice[i]= jedinice[i]-B;
                res[i][2]=B;
                B=0;
            }
            else{
                res[i][2]=jedinice[i];
                B-=jedinice[i];
                jedinice[i]=0;
                continue;
            }
            if (O<jedinice[i]){
                cout<<"nemoguce";
                return 0;
            }
            
            else{
                res[i][0]=jedinice[i];
                O-=jedinice[i];
                jedinice[i]=0;
                continue;
            }
            
        }
    }
    cout<<"moguce"<<endl;
    
    for (auto i =0; i < p ; i ++){
        for (auto j=0; j< 4; j ++){
            cout<<res[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}