#include <iostream>

using namespace std;

int main()
{
    int n,o,a,b,ab,p,br=0;
    string k;
    cin>>n>>o>>a>>b>>ab;
    int lo[n],la[n],lb[n],lab[n],blab[n],bli[n];
    for(int i=0;i<n;i++){
        cin>>k>>p;
        if(k=="O")
            if(p>o){
                cout<<"nemoguce";
                return 0;
            }
            else{
                lo[i]=p;
                la[i]=0;
                lb[i]=0;
                lab[i]=0;
                o=o-p;
            }
        if(k=="A"){
            if(p>a+o){
                cout<<"nemoguce";
                return 0;
            }
            else if(p<=a){
                lo[i]=0;
                la[i]=p;
                lb[i]=0;
                lab[i]=0;
                a=a-p;
            }
            else{
                lo[i]=p-a;
                la[i]=a;
                lb[i]=0;
                lab[i]=0;
                o=o+a-p;
                a=0;
            }
        }
        if(k=="B"){
            if(p>b+o){
                cout<<"nemoguce";
                return 0;
            }
            else if(p<=b){
                lo[i]=0;
                la[i]=0;
                lb[i]=p;
                lab[i]=0;
                b=b-p;
            }
            else{
                lo[i]=p-b;
                la[i]=0;
                lb[i]=b;
                lab[i]=0;
                o=o+b-p;
                b=0;
            }
        }
        if(k=="AB"){
            if(p>o+a+b+ab){
                cout<<"nemoguce";
                return 0;
            }
            else if(p<=ab){
                lo[i]=0;
                la[i]=0;
                lb[i]=0;
                lab[i]=p;
                ab=ab-p;
            }
            else{
                lo[i]=0;
                la[i]=0;
                lb[i]=0;
                lab[i]=0;
                blab[br]=p;
                bli[br]=i;
                br++;
            }
        }
    }
    for(int i=0;i<br;i++){
        if(blab[i]>o+a+b+ab){
            cout<<"nemoguce";
            return 0;
        }
        else{
            if(blab[i]<=o){
                lo[bli[i]]=blab[i];
                la[bli[i]]=0;
                lb[bli[i]]=0;
                lab[bli[i]]=0;
                o=o-blab[i];
            }
            else if(blab[i]<=o+a){
                lo[bli[i]]=o;
                la[bli[i]]=blab[i]-o;
                lb[bli[i]]=0;
                lab[bli[i]]=0;
                a=a-blab[i]+o;
            }
            else if(blab[i]<=o+a+b){
                lo[bli[i]]=o;
                la[bli[i]]=a;
                lb[bli[i]]=blab[i]-o-a;
                lab[bli[i]]=0;
                b=b-blab[i]+o+a;
            }
            else{
                lo[bli[i]]=o;
                la[bli[i]]=a;
                lb[bli[i]]=b;
                lab[bli[i]]=blab[i]-o-a-b;
                ab=ab-blab[i]+o+a+b;
            }
        }
    }
    cout<<"moguce"<<endl;
    for(int i=0;i<n;i++)
        cout<<lo[i]<<" "<<la[i]<<" "<<lb[i]<<" "<<lab[i]<<endl;
    return 0;
}