#include<iostream>
using namespace std;
struct pat{bool a;bool b;int d;};
int main(){
    int n,os,as,bs,abs,i;string t;cin>>n>>os>>as>>bs>>abs;
    pat l[n];int o[n],a[n],b[n],ab[n];
    for(int c=0;c<n;c++){cin>>t>>i;l[c].a=(t=="A"||t=="AB");l[c].b=(t=="B"||t=="AB");l[c].d=i;o[c]=0;a[c]=0;b[c]=0;ab[c]=0;}
    for(int c=0;c<n;c++){pat&p=l[c];
        if(p.a&&p.b){if(p.d<=abs){abs-=p.d;ab[c]+=p.d;p.d=0;}else{ab[c]+=abs;p.d-=abs;abs=0;}}
        else if(p.a){if(p.d<=as){as-=p.d;a[c]+=p.d;p.d=0;}else{a[c]+=as;p.d-=as;as=0;if(p.d<=os){os-=p.d;o[c]+=p.d;p.d=0;}else{cout<<"nemoguce";return 0;}}}
        else if(p.b){if(p.d<=bs){bs-=p.d;b[c]+=p.d;p.d=0;}else{b[c]+=bs;p.d-=bs;bs=0;if(p.d<=os){os-=p.d;o[c]+=p.d;p.d=0;}else{cout<<"nemoguce";return 0;}}}
        else{if(p.d<=os){os-=p.d;o[c]+=p.d;p.d=0;}else{cout<<"nemoguce";return 0;}}
    }for(int c=0;c<n;c++){pat&p=l[c];
        if(p.a&&p.b&&p.d){if(p.d<=as){as-=p.d;a[c]+=p.d;p.d=0;}else{a[c]+=as;p.d-=as;as=0;if(p.d<=bs){bs-=p.d;b[c]+=p.d;p.d=0;}else{b[c]+=bs;p.d-=bs;bs=0;if(p.d<=os){os-=p.d;o[c]+=p.d;p.d=0;}else{cout<<"nemoguce";return 0;}}}}
    }cout<<"moguce"<<endl;
    for(int c=0;c<n;c++)cout<<o[c]<<' '<<a[c]<<' '<<b[c]<<' '<<ab[c]<<endl;
    return 0;}