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

int main()
{
    int n,o,a,b,ab;
    cin>> n >> o >> a >> b >> ab;
    string pac[n];
    int jed[n],op[n],ap[n],abp[n],bp[n];
    for (int i=0;i<n;i++){
        ap[i]=0;
        op[i]=0;
        bp[i]=0;
        abp[i]=0;
    }
    for (int i=0;i<n;i++){
        cin>> pac[i] >> jed[i];
        }
    for (int i=0;i<n;i++){

    if (pac[i]=="O"&&jed[i]<=o){
        o-=jed[i];
        op[i]+=jed[i];
        }
    else if (pac[i]=="O"&&jed[i]>o){
        cout<<"nemoguce"; return 0;
    }
    else if (pac[i]=="A"&&jed[i]<=o+a){
            if (o!=0&&a!=0){
                if (a>=jed[i]){a-=jed[i];ap[i]+=jed[i];}
                else {o-=jed[i]-a;ap[i]+=a;op[i]+=jed[i]-a;a=0;}
            }
            else if (o==0&&a!=0){
                a-=jed[i];ap[i]+=jed[i];
            }
            else if (a==0&&o!=0){
                o-=jed[i];op[i]+=jed[i];
            }
            else {
                ap[i]=0;
                op[i]=0;
                bp[i]=0;
                abp[i]=0;
            }
        }
        else if (pac[i]=="A"&&jed[i]>a+o){
        cout<<"nemoguce"; return 0;
    }
         else if (pac[i]=="B"&&jed[i]<=o+b){
            if (o!=0&&b!=0){
                if (b>=jed[i]){b-=jed[i];bp[i]+=jed[i];}
                else {o-=jed[i]-b;bp[i]+=b;op[i]+=jed[i]-b;b=0;}
            }
            else if (o==0&&b!=0){
                b-=jed[i];bp[i]+=jed[i];
            }
            else if (b==0&&o!=0){
                o-=jed[i];op[i]+=jed[i];
            }
            else {
                ap[i]=0;
                op[i]=0;
                bp[i]=0;
                abp[i]=0;
            }
         }
         else if (pac[i]=="B"&&jed[i]>b+o){
        cout<<"nemoguce"; return 0;
        }
        else if (jed[i]>a+b+ab+o){
                    cout <<"nemoguce";
                    return 0;
                }
            else if (pac[i]=="AB"&&jed[i]<=ab+o+b+a){

                 if (a>=jed[i]){a-=jed[i];ap[i]+=jed[i];}
                else if (b>=jed[i]){b-=jed[i];bp[i]+=jed[i];}
                else if (ab>=jed[i]){ab-=jed[i];abp[i]+=jed[i];}
                else if (o>=jed[i]) {o-=jed[i]-a;ap[i]+=a;op[i]+=jed[i]-a;a=0;}
                else {
                    if (o==0){
                        if (ab==0){
                            if (b>a){
                                ap[i]+=jed[i]-b;
                                b-=jed[i]-a;
                                bp[i]+=jed[i]-a;
                            }
                            else {
                                bp[i]+=jed[i]-a;
                                a-=jed[i]-b;
                                ap[i]+=jed[i]-b;
                            }
                        }
                        else{
                            if (ab +a>=jed[i]){
                                if (ab>a){
                                ap[i]+=jed[i]-ab;
                                ab-=jed[i]-a;
                                abp[i]+=jed[i]-a;
                            }
                                else {
                                abp[i]+=jed[i]-a;
                                a-=jed[i]-ab;
                                ap[i]+=jed[i]-ab;
                                }
                            }
                        else if (ab +b>=jed[i]){
                                if (ab>b){
                                bp[i]+=jed[i]-ab;
                                ab-=jed[i]-b;
                                abp[i]+=jed[i]-b;
                            }
                                else {
                                abp[i]+=jed[i]-b;
                                b-=jed[i]-ab;
                                bp[i]+=jed[i]-ab;
                                }
                            }
                        }
                    }
                    else if (a==0){
                        if (ab==0){
                                if (b>o){
                                op[i]+=jed[i]-b;
                                b-=jed[i]-o;
                                bp[i]+=jed[i]-o;
                                }
                                else {
                                bp[i]+=jed[i]-o;
                                o-=jed[i]-b;
                                op[i]+=jed[i]-b;
                                }
                            }

                            else {
                                if (ab+o>=jed[i]){
                            if (ab>o){
                                op[i]+=jed[i]-ab;
                                ab-=jed[i]-o;
                                abp[i]+=jed[i]-o;
                                }
                            else {
                                abp[i]+=jed[i]-o;
                                o-=jed[i]-ab;
                                op[i]+=jed[i]-ab;
                                }
                            }
                             else if (ab +b>=jed[i]){
                                if (ab>a){
                                bp[i]+=jed[i]-ab;
                                ab-=jed[i]-b;
                                abp[i]+=jed[i]-b;
                            }
                                else {
                                abp[i]+=jed[i]-b;
                                b-=jed[i]-ab;
                                bp[i]+=jed[i]-ab;
                                    }
                                }
                            }

                            }
                    else if (b==0){
                            if(ab==0){
                                if (a>o){
                                op[i]+=jed[i]-a;
                                a-=jed[i]-o;
                                ap[i]+=jed[i]-o;
                                }
                                else {
                                ap[i]+=jed[i]-o;
                                o-=jed[i]-a;
                                op[i]+=jed[i]-b;
                                }
                            }
                            else{
                              if (a+o>jed[i]){
                                if (a>o){
                                op[i]+=jed[i]-a;
                                a-=jed[i]-o;
                                ap[i]+=jed[i]-o;
                                }
                                else {
                                ap[i]+=jed[i]-o;
                                o-=jed[i]-a;
                                op[i]+=jed[i]-b;
                                    }
                                }
                                if (ab+o>=jed[i]){
                            if (ab>o){
                                op[i]+=jed[i]-ab;
                                ab-=jed[i]-o;
                                abp[i]+=jed[i]-o;
                                }
                            else {
                                abp[i]+=jed[i]-o;
                                o-=jed[i]-ab;
                                op[i]+=jed[i]-ab;
                                }
                            }
                             else if (ab +b>=jed[i]){
                                if (ab>a){
                                bp[i]+=jed[i]-ab;
                                ab-=jed[i]-b;
                                abp[i]+=jed[i]-b;
                            }
                                else {
                                abp[i]+=jed[i]-b;
                                b-=jed[i]-ab;
                                bp[i]+=jed[i]-ab;
                                    }
                                }

                            }

                        }

                      }

                }
            }


    cout<< "moguce"<<endl;
    for (int i=0;i<n;i++){

        cout << op[i]<<" " << ap[i]<<" " << bp[i]<<" " << abp[i] << endl;
    }

    return 0;
}