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

struct bolesnik{
    string gr;
    int j;
};

struct jedinice{
    int o,a,b,c;
};

int main(){
    int n,o,a,b,c,br=0;
    cin>>n;
    cin>>o>>a>>b>>c;
    bolesnik x[n];
    jedinice y[n];
    bool r=true;
    for(int i=0;i<n;i++) cin>>x[i].gr>>x[i].j;
    for(int i=0;i<n;i++){
        if(x[i].gr=="O"){
            if(x[i].j>o){
                r=false;
                break;
            }
            else{
                o-=x[i].j;
                y[i].o=x[i].j;
                y[i].a=y[i].b=y[i].c=0;
            }
        }
        else if(x[i].gr=="A"){
            if(x[i].j>a){
                if(x[i].j-a>o){
                    r=false;
                    break;
                }
                else{
                    y[i].a=a;
                    y[i].o=x[i].j-a;
                    y[i].b=y[i].c=0;
                    a=0;
                    o-=y[i].o;
                }
            }
            else{
                a-=x[i].j;
                y[i].a=x[i].j;
                y[i].o=y[i].b=y[i].c=0;
            }
        }
        else if(x[i].gr=="B"){
            if(x[i].j>b){
                if(x[i].j-b>o){
                    r=false;
                    break;
                }
                else{
                    y[i].b=b;
                    y[i].o=x[i].j-b;
                    y[i].a=y[i].c=0;
                    b=0;
                    o-=y[i].o;
                }
            }
            else{
                b-=x[i].j;
                y[i].b=x[i].j;
                y[i].o=y[i].a=y[i].c=0;
            }
        }
        else if(x[i].gr=="AB") br+=x[i].j; 
    }
    if(r==false or br>(a+b+c+o)) cout<<"nemoguce";
    else{
        for(int i=0; i<n; i++){
            if(x[i].gr=="AB"){
                //y[i].o=y[i].a=y[i].b=y[i].c=0;
                if(x[i].j<=c){
                    y[i].c=x[i].j;
                    y[i].o=y[i].a=y[i].b=0;                        
                    c-=x[i].j;
                }
                else{
                    y[i].c=c;
                    c=0;
                    if((x[i].j-y[i].c)<=b){
                        y[i].b=x[i].j-y[i].c;
                        b-=y[i].b;
                        y[i].o=y[i].a=0;
                    }
                    else{
                        y[i].b=b;
                        b=0;
                        if((x[i].j-y[i].c-y[i].b)<=a){
                            y[i].a=x[i].j-y[i].b-y[i].c;
                            a-=y[i].a;
                            y[i].o=0;
                        }
                        else if(x[i].j-y[i].a-y[i].b-y[i].c<=o){
                            y[i].o=x[i].j-y[i].a-y[i].b-y[i].c;
                            o-=y[i].o;
                        }
                    }
                }
            }
        }
        cout<<"moguce"<<endl;
        for(int i=0;i<n;i++) cout<<y[i].o<<" "<<y[i].a<<" "<<y[i].b<<" "<<y[i].c<<endl;
    }
}