#include <iostream>
using namespace std;
int main(){
    long long n,o,a,b,ab;
    int matra[10000][4];
    string c;
    long long a1;
    cin>>n>>o>>a>>b>>ab;
    for(int i=0;i<n;++i){
        for(int j=0;j<4;++j){
            matra[i][j]=0;
        }
    }
    for(int i=0;i<n;++i){
        cin>>c>>a1;
        if(c=="O"){
            if(a1>o){
                cout<<"nemoguce";
                return 0;
            }
            matra[i][0]=a1;
            o-=a1;
        }
        else if(c=="A"){
            if(a1>a+o){
                cout<<"nemoguce";
                return 0;
                
            }
            if(a1>a){
                long long e=a1-a;
                matra[i][1]=a;
                a-=a;
                matra[i][0]=e;
                o-=e;
            }
            else if(a1<a){
                matra[i][1]=a1;
                a-=a1;
            }
        }
        else if(c=="B"){
            if(a1>b+o){
                cout<<"nemoguce";
                return 0;
            }
            if(a1>b){
                long long e=a1-b;
                matra[i][2]=b;
                b-=b;
                matra[i][0]=e;
                o-=e;
            }
            else if(a1<b){
                matra[i][2]=a1;
                b-=a1;
            }
        }
        else if(c=="AB"){
            if(a1>a+o+b+ab){
                cout<<"nemoguce";
                return 0;
            }
            if(a1<ab){
                matra[i][3]=a1;
                ab-=a1;
            }
            else if(a1==ab){
                matra[i][3]=a1;
                ab-=ab;
            }
            else if(a1>ab and a1<=ab+b){
                matra[i][3]=ab;
                a1-=ab;
                ab-=ab;
                matra[i][2]=a1;
                b-=a1;
            }
            else if(a1>ab and a1<=ab+b+a){
                matra[i][3]=ab;
                a1-=b;
                a1-=ab;
                ab-=ab;
                matra[i][2]=b;
                b-=b;
                matra[i][1]=a1;
                a-=a1;
            }
            else{
                matra[i][3]=ab;
                a1-=a;
                a1-=b;
                a1-=ab;
                ab-=ab;
                matra[i][2]=b;
                b-=b;
                matra[i][1]=a;
                a-=a;
                matra[i][0]=a1;
                o-=a1;
            }
        }
    }
    cout<<"moguce"<<endl;
    for(int i=0;i<n;++i){
        for(int j=0;j<4;++j){
            cout<<matra[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}