#include <bits/stdc++.h>
#include <string>

#define ll long long
using namespace std;

int main()
{
    ll n;cin>>n;
    ll O, A, B, AB;
    cin>>O>>A>>B>>AB;
    //string s1[n];
    string s[n];
    ll x[n];
    for(int i = 0; i < n; i++){
        cin>>s[i]>>x[i];
        /*cout<<"s1["<<i<<"] "<<s1[i]<<endl;
        int j = 0;
        s[i]="";
        if(s1[i][0]=='A'){
            s[i] = "A";
            j= 2;
        }


        string y="";
        while(j<s1[i].length()){
            y+=s1[i][j];
            j++;
        }
        cout<<"y["<<i<<"] "<<y<<endl;
        stringstream geek(y);
        x[i] = 0;
        geek >> x[i];
        cout<<"x[i] "<<x[i]<<endl;*/
    }
    //ako je kod mutav, proveri ovaj segment iznad...

    ll res[n][4];
    for(int i = 0;i<n;i++){
        for(int j = 0;j<4;j++){
            res[i][j] = 0;
        }
    }
    bool nemoguce = false;
    for(int i = 0; i<n; i++){
        if(s[i]=="O"){
            if(O-x[i]>=0){
                O-=x[i];
                res[i][0] = x[i];
            }
            else{
                nemoguce = true;
                break;
            }
        }
    }
    /// svi iz grupe O su reseni
    /// res0 = O; res1 = A; res2 = B; res3 = AB;

    for(int i = 0; i<n; i++){
        if(s[i]=="A"){
            if(A-x[i]>=0){
                A-= x[i];
                res[i][1] = x[i];
            }
            else if((A+O)-x[i]>=0){
                res[i][1] = A;
                x[i]-=A;
                A = 0;

                O-=x[i];
                res[i][0] = x[i];
            }
            else{
                nemoguce = true;
                break;
            }
        }
    }
    ///svi iz grupe A su reseni

    for(int i = 0; i<n; i++){
        if(s[i]=="B"){
            if(B-x[i]>=0){
                B-= x[i];
                res[i][2] = x[i];
            }
            else if((B+O)-x[i]>=0){
                res[i][2] = B;
                x[i]-=B;
                B = 0;

                O-=x[i];
                res[i][0] = x[i];
            }
            else{
                nemoguce = true;
                break;
            }
        }
    }
    /// svi iz grupe B su reseni

    for(int i = 0;i<n;i++){
        if(s[i]=="AB"){
            if(O-x[i]>=0){
                O -=x[i];
                res[i][0] = x[i];
            }
            else if((A+O)-x[i]>=0){
                res[i][0] = O;
                x[i]-=O;
                O = 0;

                A -= x[i];
                res[i][1] = x[i];
            }
            else if((A+O+B)>=x[i]){
                res[i][0] = O;
                x[i]-=O;
                O = 0;
                res[i][1] = A;
                x[i]-=A;
                A = 0;

                B -= x[i];
                res[i][2] = x[i];
            }
            else if((A+O+B+AB)>=x[i]){
                res[i][0] = O;
                x[i]-=O;
                O = 0;
                res[i][1] = A;
                x[i]-=A;
                A = 0;
                res[i][2] = B;
                x[i]-=B;
                B = 0;

                AB -= x[i];
                res[i][3] = x[i];
            }
            else{
                nemoguce = true;
                break;
            }
        }
    }
    ///svi pacijenti reseni, ili sistem umro u medjuvremenu
    if(nemoguce){
        cout<<"nemoguce";
    }
    else{
        cout<<"moguce"<<endl;
        for(int i = 0; i<n; i++){
            for(int j = 0; j<4; j++){
                if(j!=3){
                    cout<<res[i][j]<<" ";
                }
                else{
                    cout<<res[i][j];
                }
            }
            cout<<endl;
        }
    }
}