#include <bits/stdc++.h>
#define N 10005
using namespace std;
//patients
int ptc[N];

//O, A,B ,C = AB
char ptcT[N];

int Of[N];
int Af[N];
int Bf[N];
int ABf[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int o,a,b,ab;
    cin>>o>>a>>b>>ab;
    for(int i =0;i<n;i++){
        string s;
        cin>>s;
        if(s=="A"){ptcT[i] = 'A';}
        if(s=="B"){ptcT[i] = 'B';}
        if(s=="O"){ptcT[i] = 'O';}
        if(s=="AB"){ptcT[i] = 'C';}
        cin>>ptc[i];
    }   
    //first we fill the O-s
    for(int i =0;i<n;i++){
        if(ptcT[i]=='O'){
            //we fill it with
            int fill = min(ptc[i],o);
            ptc[i]-=fill;
            Of[i]+=fill;
            o-=fill;
        }
    }
    //then A and B with A and B
     for(int i =0;i<n;i++){
        if(ptcT[i]=='A'){
            //we fill it with
            int fill = min(ptc[i],a);
            ptc[i]-=fill;
            Af[i]+=fill;
            a-=fill;
        }
        if(ptcT[i]=='B'){
            //we fill it with
            int fill = min(ptc[i],b);
            ptc[i]-=fill;
             Bf[i]+=fill;
            b-=fill;
        }
    }
    //then we fill A and B with O
    for(int i =0;i<n;i++){
        if(ptcT[i]=='A'||ptc[i]=='B'){
            //we fill it with
            int fill = min(ptc[i],o);
            ptc[i]-=fill;
            Of[i]+=fill;
            o-=fill;
        }
    }
    //then we fill AB with anything left
    for(int i =0;i<n;i++){
        if(ptcT[i]=='C'){
            //we fill it with O
            int fill = min(ptc[i],o);
            ptc[i]-=fill;
             Of[i]+=fill;
            o-=fill;
            //we fill it with A
             fill = min(ptc[i],a);
            ptc[i]-=fill;
             Af[i]+=fill;
            a-=fill;
            //we fill it with B
             fill = min(ptc[i],b);
            ptc[i]-=fill;
             Bf[i]+=fill;
            b-=fill;
            //we fill it with AB
             fill = min(ptc[i],ab);
            ptc[i]-=fill;
             ABf[i]+=fill;
            ab-=fill;
        }
    }
    //now we check if everything is filled
    //aka every ptc is 0
    for(int i =0;i<n;i++){if(ptc[i]){goto IMP;}}
    cout<<"moguce"<<endl;
    for(int i =0;i<n;i++){
        cout<<Of[i]<<Af[i]<<Bf[i]<<ABf[i]<<endl;

    }
    return 0;

    IMP:
        cout<<"nemoguce"<<endl;
        return 0;
}