#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int o, a, b, ab;
    cin >> o >> a >> b >> ab;
    int brj;
    string op;
    vector<int> v1, v2, v3, v4;
    int o1, a1, b1, ab1;
    for(int i=0; i<n; i++){
        cin >> op >> brj;
        if(op=="O"){
            o1 = brj;
            a1=0;
            b1=0;
            ab1=0;
            o = o - o1;
        }
        else if(op=="A"){
            if(a>=brj){
                o1=0;
                a1=brj;
                b1=0;
                ab1=0;
                o1=0;
                a=a-a1;
            }
            else{
                o1=brj-a;
                a1=a;
                b1=0;
                ab1=0;
                o=o-o1;
                a=0;
            }
        }
        else if(op=="B"){
            if(b>=brj){
                o1=0;
                a1=0;
                b1=brj;
                ab1=0;
                o1=0;
                b=b-b1;
            }
            else{
                o1=brj-b;
                a1=0;
                b1=b;
                ab1=0;
                o=o-o1;
                b=0;
            }
        }
        else if(op=="AB"){
            if(ab>=brj){
                o1=0;
                a1=0;
                b1=0;
                ab1=brj;
                o1=0;
                ab=ab-ab1;
            }
            else {
                o1=brj-ab;
                a1=0;
                b1=0;
                ab1=ab;
                o=o-o1;
                ab=0;
        }
    }
v1.push_back(o1);
v2.push_back(a1);
v3.push_back(b1);
v4.push_back(ab1);

}
if(o>=0&&a>=0&&b>=0&&ab>=0){
        cout << "moguce" << endl;
        for(int i=0; i<n; i++){
              cout << v1[i] << v2[i] << v3[i] << v4[i] << endl;;
        }
    }
    else{
        cout << "nemoguce";
    }
return 0;
}