#include <bits/stdc++.h>

using namespace std;

#define ll long long
const ll MAXN=1e6+5,INF=1e9,MOD=1e9+7;
const double EPS=1e-9;
#define fi first
#define se second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mid (l+r)/2
#define sz(a) int((a).size())
#define all(a) a.begin(),a.end()
#define mod 1000000007LL
#define pb push_back
#define endl "\n"
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
#define PRINTvec(x) { cerr<<#x<<"-"; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; }

ll n,k,q,x,y,z,l,r,res=0;
string s,t;
ifstream in;
ofstream out;

#ifdef ONLINE_JUDGE
    #define in cin
    #define out cout
#endif

int ko,ka,kb,kab;

struct covek{
    string krv; int jed,ind;
    int o,a,b,ab;
    void input(){
        cin>>krv>>jed;
        o=0,a=0,b=0,ab=0;
    }
    void output(){
        PRINT(ind); PRINT(krv); PRINT(jed); PRINT(o); PRINT(a); PRINT(b); PRINT(ab);
    }
};

vector<covek> co,ca,cb,cab;
vector<covek> ans;

void solve(){
    cin>>n;
    cin>>ko>>ka>>kb>>kab;
    ans.resize(n);
    for(int i=0;i<n;i++){
        covek tmp;
        tmp.input();
        tmp.ind=i;
        if(tmp.krv=="O"){
            co.pb(tmp);
        }
        else if(tmp.krv=="A"){
            ca.pb(tmp);
        }
        else if(tmp.krv=="B"){
            cb.pb(tmp);
        }
        else{
            cab.pb(tmp);
        }
    }
    bool good=true;
    for(covek& x:co){
        if(x.jed){
            x.o=min(ko,x.jed);
            ko-=x.o;
            x.jed-=x.o;
        }
        if(x.jed) good=false;
    }
    for(covek& x:ca){
        if(x.jed){
            x.a+=min(ka,x.jed);
            ka-=x.a;
            x.jed-=x.a;
        }
        if(x.jed){
            x.o+=min(ko,x.jed);
            ko-=x.o;
            x.jed-=x.o;
        }
        if(x.jed) good=false;
    }
    for(covek& x:cb){
        if(x.jed){
            x.b+=min(kb,x.jed);
            kb-=x.b;
            x.jed-=x.b;
        }
        if(x.jed){
            x.o+=min(ko,x.jed);
            ko-=x.o;
            x.jed-=x.o;
        }
        if(x.jed) good=false;
    }
    for(covek& x:cab){
        if(x.jed){
            x.o+=min(ko,x.jed);
            ko-=x.o;
            x.jed-=x.o;
        }
        if(x.jed){
            x.a+=min(ka,x.jed);
            ka-=x.a;
            x.jed-=x.a;
        }
        if(x.jed){
            x.b+=min(kb,x.jed);
            kb-=x.b;
            x.jed-=x.b;
        }
        if(x.jed){
            x.ab+=min(kab,x.jed);
            kab-=x.ab;
            x.jed-=x.ab;
        }
        if(x.jed) good=false;
    }
    if(!good){ cout<<"nemoguce"<<endl; return; }
    else{
        cout<<"moguce"<<endl;
        for(covek& x:co){
            ans[x.ind].o=x.o;
            ans[x.ind].a=x.a;
            ans[x.ind].b=x.b;
            ans[x.ind].ab=x.ab;
        }
        for(covek& x:ca){
            ans[x.ind].o=x.o;
            ans[x.ind].a=x.a;
            ans[x.ind].b=x.b;
            ans[x.ind].ab=x.ab;
        }
        for(covek& x:cb){
            ans[x.ind].o=x.o;
            ans[x.ind].a=x.a;
            ans[x.ind].b=x.b;
            ans[x.ind].ab=x.ab;
        }
        for(covek& x:cab){
            ans[x.ind].o=x.o;
            ans[x.ind].a=x.a;
            ans[x.ind].b=x.b;
            ans[x.ind].ab=x.ab;
        }
    }
    for(int i=0;i<n;i++){
        cout<<ans[i].o<<" "<<ans[i].a<<" "<<ans[i].b<<" "<<ans[i].ab<<endl;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        in.open("D:\\UROS\\Programiranje\\input.in",ios::in);
        out.open("D:\\UROS\\Programiranje\\output.out",ios::trunc | ios::out);
    #endif
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);'
    int t;
    ///cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}