#include <bits/stdc++.h>

using namespace std;
vector<pair<int, string> > v;
int o1[10010];
int a1[10010];
int b1[10010];
int ab1[10010];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    bool t=1;
    int n,o,a,b,ab,x;
    cin>>n>>o>>a>>b>>ab;
    for(int i=0;i<n;i++){
        cin>>s>>x;
        v.push_back(make_pair(x,s));
    }
    for(int i=0;i<n;i++){
        if(v[i].second=="O"){
            if(v[i].first<=o){
                o1[i]=v[i].first;
                o-=v[i].first;
            }
            else
                t=0;
        }
    }
    for(int i=0;i<n;i++){
        if(v[i].second=="A"){
            if(v[i].first<=a){
                a1[i]=v[i].first;
                a-=v[i].first;
            }
            else{
                v[i].first-=a;
                a1[i]=a;
                a=0;
                if(v[i].first<=o){
                    o1[i]=v[i].first;
                    o-=v[i].first;
                }
                else
                    t=0;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(v[i].second=="B"){
            if(v[i].first<=b){
                b1[i]=v[i].first;
                b-=v[i].first;
            }
            else{
                v[i].first-=b;
                b1[i]=b;
                b=0;
                if(v[i].first<=o){
                    o1[i]=v[i].first;
                    o-=v[i].first;
                }
                else
                    t=0;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(v[i].second=="AB"){
            if(v[i].first<=a){
                a1[i]=v[i].first;
                a-=v[i].first;
            }
            else{
                v[i].first-=a;
                a1[i]=a;
                a=0;
                if(v[i].first<=o){
                    o1[i]=v[i].first;
                    o-=v[i].first;
                }
                else{
                    v[i].first-=o;
                    o1[i]=o;
                    o=0;
                    if(v[i].first<=b){
                        b1[i]=v[i].first;
                        b-=v[i].first;
                    }
                    else{
                        v[i].first-=b;
                        b1[i]=b;
                        b=0;
                        if(v[i].first<=ab){
                            ab1[i]=v[i].first;
                            ab-=v[i].first;
                        }
                        else
                            t=0;
                    }
                }
            }
        }
    }
    if(t){
        cout<<"moguce\n";
        for(int i=0;i<n;i++)
            cout<<o1[i]<<" "<<a1[i]<<" "<<b1[i]<<" "<<ab1[i]<<"\n";
    }
    else
        cout<<"nemoguce";
    return 0;
}