#include <bits/stdc++.h>
using namespace std;
bool enough(vector<int> available, vector<int> needed){
    
}
int main(){
    vector<int> available(4),needed(4),available1(4);//O=0,A=1,B=2,AB=3
    int n,sum=0;
    cin>>n>>available[0]>>available[1]>>available[2]>>available[3];
    vector<int> red(n), treba(n);
    for(int i=0;i<n;i++){
        string a; int b,c;
        cin>>a>>b;
        c=(a=="O"?0:(a=="A"?1:(a=="B"?2:3)));
        red[i]=c;
        needed[c]+=b;
        treba[i]=b;
    }
    for(int i=0;i<4;i++){
        available1[i]=available[i];
    }
    if(needed[0]>available[0]){
        cout<<"nemoguce";
    }else{
        available[0]-=needed[0];
        needed[0]=0;
        if((needed[1]>available[0]+available[1])||(needed[2]>available[0]+available[2])||(needed[1]+needed[2]>available[0]+available[1]+available[2])){
            cout<<"nemoguce";
        }else{
            for(int i=1;i<=2;i++){
                if(needed[i]>=available[i]){
                    needed[i]-=available[i];
                    available[i]=0;
                    available[0]-=needed[i];
                    needed[i]=0;
                }else{
                    needed[i]-=available[i];
                    
                }
            }
            if(needed[3]>available[0]+available[1]+available[2]){
                cout<<"nemoguce";
            }else{
                cout<<"moguce";
                for(int i=0;i<n;i++){
                    if(red[i]=0){
                        cout<<treba[i]<<" 0 0 0\n";
                        available1[0]-=treba[i];
                    }else{
                        for(int j=1;j<=2;j++){
                            if(red[i]==j){
                                if(treba[i]<=available1[0]){
                                    int x= available1[0];
                                    
                                }
                            }
                        }
                    }
                }
            }
        }
    }

}