#include<bits/stdc++.h>
#define MOD 1000000007LL
#define ll long long

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int o,a,b,ab;
    int o1=0,a1=0,b1=0,ab1=0;
    cin>>o>>a>>b>>ab;
    vector<pair<int,int> > o2;
    vector<pair<int,int> > a2;
    vector<pair<int,int> > b2;
    vector<pair<int,int> > ab2;
    pair<pair<int,int>,pair<int,int> > seq[10010];
    for(int i=0;i<n;i++){
        string s;
        int y;
        cin>>s>>y;
        pair<int,int> x=make_pair(i,y);
        if(s=="O"){
            o2.push_back(x);
            o1+=y;
        }
        if(s=="A"){
            a2.push_back(x);
            a1+=y;
        }
        if(s=="B"){
            b2.push_back(x);
            b1+=y;
        }
        if(s=="AB"){
            ab2.push_back(x);
            ab1+=y;
        }
    }
    if(o1>o || a1>a+o-o1 || b1>b+(a1-a-o+o1) || b1>b+o-o1 || ab1>ab+a-a1+o-o1+b-b1){
        cout<<"nemoguce";
        return 0;
    }
    cout<<"moguce"<<endl;
    for(int i=0;i<o2.size();i++){
        int idx=o2[i].first;
        int num=o2[i].second;
        seq[idx].first.first=num;
        seq[idx].first.second=0;
        seq[idx].second.first=0;
        seq[idx].second.second=0;
        o-=num;
    }
    for(int i=0;i<a2.size();i++){
        int idx=a2[i].first;
        int num=a2[i].second;
        seq[idx].first.first=num-min(a,num);
        seq[idx].first.second=min(a,num);
        seq[idx].second.first=0;
        seq[idx].second.second=0;
        a-=min(a,num);
        o-=num-min(a,num);
    }
    for(int i=0;i<b2.size();i++){
        int idx=b2[i].first;
        int num=b2[i].second;
        seq[idx].first.first=num-min(b,num);
        seq[idx].first.second=0;
        seq[idx].second.first=min(b,num);
        seq[idx].second.second=0;
        b-=min(b,num);
        o-=num-min(b,num);
    }
    for(int i=0;i<ab2.size();i++){
        int idx=ab2[i].first;
        int num=ab2[i].second;
        seq[idx].first.first=num-min(num-min(num-min(ab,num),a)-min(ab,num),b)-min(num-min(ab,num),a)-min(ab,num);
        seq[idx].first.second=min(num-min(ab,num),a);
        seq[idx].second.first=min(num-min(num-min(ab,num),a)-min(ab,num),b);
        seq[idx].second.second=min(ab,num);
        ab-=min(ab,num);
        a-=min(num-min(ab,num),a);;
        b-=min(num-min(num-min(ab,num),a),b);
        o-=num-min(num-min(num-min(ab,num),a),b);
    }
    for(int i=0;i<n;i++){
        cout<<seq[i].first.first<<" "<<seq[i].first.second<<" "<<seq[i].second.first<<" "<<seq[i].second.second<<endl;
    }
    return 0;
}