#include <bits/stdc++.h>
using namespace std;

vector<int> Op, Ap, Bp, ABp, Ored, Ared, Bred, ABred;
int Og[10000], Ag[10000], Bg[10000], ABg[10000];

int main() {
    int N, O, A, B, AB, k, t=0;
    string s;
    cin>>N>>O>>A>>B>>AB;
    for(int i=0; i<N; i++) {
        cin>>s>>k;
        if(s=="O") {
            Op.push_back(k);
            Ored.push_back(i);
        }
        if(s=="A") {
            Ap.push_back(k);
            Ared.push_back(i);
        }
        if(s=="B") {
            Bp.push_back(k);
            Bred.push_back(i);
        }
        if(s=="AB") {
            ABp.push_back(k);
            ABred.push_back(i);
        }
    }
    for(int i=0; i<Op.size(); i++) {
        O-=Op[i];
        Og[Ored[i]]=Op[i];
    }
    if(O<0) {
        cout<<"nemoguce";
        return 0;
    }
    for(int i=0; i<Ap.size(); i++) {
        if(A<Ap[i]) {
            Ap[i]-=A;
            Ag[Ared[i]]=A;
            A=0;
        }
        O-=Ap[i];
        Og[Ared[i]]=Ap[i];
    }
    if(O<0) {
        cout<<"nemoguce";
        return 0;
    }
    for(int i=0; i<Bp.size(); i++) {
        if(B<Bp[i]) {
            Bp[i]-=B;
            Bg[Bred[i]]=B;
            B=0;
        }
        O-=Bp[i];
        Og[Bred[i]]=Bp[i];
    }
    if(O<0) {
        cout<<"nemoguce";
        return 0;
    }
    k=0;
    for(int i=0; i<ABp.size(); i++) {
        if(O<ABp[i]) {
            ABp[i]-=O;
            Og[ABred[i]]=O;
            O=0;
        }
        else {
            O-=ABp[i];
            Og[ABred[i]]=ABp[i];
            continue;
        }
        if(A<ABp[i]) {
            ABp[i]-=A;
            Ag[ABred[i]]=A;
            A=0;
        }
        else {
            A-=ABp[i];
            Ag[ABred[i]]=ABp[i];
            continue;
        }
        if(B<ABp[i]) {
            ABp[i]-=B;
            Bg[ABred[i]]=B;
            B=0;
        }
        else {
            B-=ABp[i];
            Bg[ABred[i]]=Bp[i];
            continue;
        }
        if(AB<ABp[i]) {
            cout<<"nemoguce";
            return 0;
        }
        else {
            AB-=ABp[i];
            ABg[ABred[i]]=ABp[i];
            continue;
        }
    }
    cout<<"moguce\n";
    for(int i=0; i<N; i++) {
        cout<<Og[i]<<' '<<Ag[i]<<' '<<Bg[i]<<' '<<ABg[i]<<'\n';
    }
    return 0;
}