#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n, zo, za, zb, zab;
    cin>>n;
    cin>>zo>>za>>zb>>zab;
    vector<int> o;
    vector<int> a;
    vector<int> b;
    vector<int> ab;
    bool l=true;
    for (int i=0; i<n; i++){
        string g;
        int p;
        cin>>g>>p;
        if (g=="O"){
            if (p>zo){
                l=false;
                break;
            }
            else{
                o.push_back(p);
                a.push_back(0);
                b.push_back(0);
                ab.push_back(0);
                zo-=p;
            }
        }
        else if (g=="A"){
            if (p>zo+za){
                l=false;
                break;
            }
            else{
                if (za>=p){
                    za-=p;
                    o.push_back(0);
                    a.push_back(p);
                    b.push_back(0);
                    ab.push_back(0);
                }
                else{
                    p-=za;
                    a.push_back(za);
                    za=0;
                    o.push_back(p);
                    zo-=p;
                    p=0;
                    b.push_back(0);
                    ab.push_back(0);
                }
            }
        }
        else if (g=="B"){
            if (p>zo+zb){
                l=false;
                break;
            }
            else{
                if (zb>=p){
                    zb-=p;
                    o.push_back(0);
                    b.push_back(p);
                    a.push_back(0);
                    ab.push_back(0);
                }
                else{
                    p-=zb;
                    b.push_back(zb);
                    zb=0;
                    o.push_back(p);
                    zo-=p;
                    p=0;
                    a.push_back(0);
                    ab.push_back(0);
                }
            }
        }
        else if (g=="AB"){
            if (p>zo+za+zb+zab){
                l=false;
                break;
            }
            else{
                if (p<=zab){
                    zab-=p;
                    ab.push_back(p);
                    a.push_back(0);
                    b.push_back(0);
                    o.push_back(0);
                    p=0;
                }
                else{
                    ab.push_back(zab);
                    p-=zab;
                    zab=0;
                    if (za>zb){
                        if (za>=p){
                            a.push_back(p);
                            za-=p;
                            p=0;
                            b.push_back(0);
                            o.push_back(0);
                        }
                        else{
                            p-=za;
                            a.push_back(za);
                            za=0;
                            if (zb>=p){
                                b.push_back(p);
                                zb-=p;
                                p=0;
                                o.push_back(0);
                            }
                            else{
                                p-=zb;
                                b.push_back(zb);
                                zb=0;
                                zo-=p;
                                o.push_back(p);
                                p=0;
                            }
                        }
                    }
                    else{
                        if (zb>=p){
                            b.push_back(p);
                            zb-=p;
                            p=0;
                            a.push_back(0);
                            o.push_back(0);
                        }
                        else{
                            p-=zb;
                            b.push_back(zb);
                            zb=0;
                            if (za>=p){
                                a.push_back(p);
                                za-=p;
                                p=0;
                                o.push_back(0);
                            }
                            else{
                                p-=za;
                                a.push_back(za);
                                za=0;
                                zo-=p;
                                o.push_back(p);
                                p=0;
                            }
                        }
                    }

                }
            }
        }
    }
    if (l==false){cout<<"nemoguce"<<endl;}
    else{
        cout << "moguce" << endl;
        for (int i=0; i<n; i++){
            cout<<o[i]<<" "<<a[i]<<" "<<b[i]<<" "<<ab[i]<<endl;
        }
    }
    return 0;
}