#include <iostream>
#include <string>
using namespace std;
int main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
    int n;
    int krv[4];
    cin >> n;
    for(int i=0;i<4;++i){
        cin >> krv[i];
    }
    string g[n];
    int br[n];
    int res[n][4];
    int gr[n];
    int ab[n];
    int k = 0;
    for(int i=0;i<n;++i){
        cin >> g[i] >> br[i];
        if(g[i]=="O"){
            gr[i]=0;
        }
        else if(g[i]=="A"){
            gr[i]=1;
        }
        else if(g[i]=="B"){
            gr[i]=2;
        }
        else {
            gr[i]=3;
            ab[k]=i;
            ++k;
        };
    }
    bool nemoguce = false;
    for(int i=0;i<n;++i){
        for(int j=3;j>=0;--j){
            if(gr[i]<=1){
                if(j<=gr[i]){
                    res[i][j]=min(krv[j],br[i]);
                    int x = krv[j];
                    krv[j]=max(0,krv[j]-br[i]);
                    br[i]=max(0,br[i]-x);
                }
                else{
                res[i][j]=0;
                }
            }
            else if (gr[i]==2){
                if(j==gr[i] || j==0){
                    res[i][j]=min(krv[j],br[i]);
                    int x = krv[j];
                    krv[j]=max(0,krv[j]-br[i]);
                    br[i]=max(0,br[i]-x);
                }
                else{
                res[i][j]=0;
                }
            }
            else {
                res[i][j]=0;
            }

        }
        if(br[i]>0&&gr[i]!=3){
            nemoguce = true;
            break;
        }
    }
    for(int i=0;i<k;++i){
        for(int j=3;j>=0;--j){
            res[ab[i]][j]=min(krv[j],br[ab[i]]);
            int x = krv[j];
            krv[j]=max(0,krv[j]-br[ab[i]]);
            br[ab[i]]=max(0,br[ab[i]]-x);
        }
        if(br[ab[i]]>0){
            nemoguce = true;
            break;
        }
    }

    if(nemoguce){
        cout << "nemoguce" << '\n';
    }
    else{
    cout << "moguce" << '\n';
    for(int i=0;i<n;++i){
        for(int j=0;j<4;++j){
            cout << res[i][j] << " ";
        }
        cout << '\n';
    }
}
    return 0;
}