package transfuzija;

import java.util.Scanner;

public class Transfuzija {

    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        int N=in.nextInt();
        int O=in.nextInt();
        int A=in.nextInt();
        int B=in.nextInt();
        int AB=in.nextInt();
        boolean nemoguce=false;
        
        int[] a=new int[N];
        String[] gr = new String[N];
        
        for(int i=0;i<N;i++){
            gr[i]=in.next();
            a[i]=in.nextInt();
        }
        
        for(int i=0;i<N;i++){
            if(nemoguce==false){
                System.out.println("moguce");
                nemoguce=true;
            }
            if(gr[i].equals("O")){
                if(O==a[i]){
                    System.out.printf("%d 0 0 0 \n", O);
                    O=O-a[i];
                }else if(O>a[i]){
                    System.out.printf("%d 0 0 0 \n", a[i]);
                    O=O-a[i];
                }else if(O<a[i]){
                    System.out.printf("nemoguce");
                    nemoguce=true;
                    System.exit(1);
                }
            }
            if(gr[i].equals("A")){
                if(a[i]<A){
                    System.out.printf("0 %d 0 0 \n", a[i]);
                    A=A-a[i];
                }else if(A==a[i]){
                    System.out.printf("0 %d 0 0 \n", A);
                    A=0;
                }else if(a[i]>A){
                    a[i]=a[1]-A;
                    if(O>a[i]){
                        O=O-a[i];
                        System.out.printf("%d %d 0 0 \n",a[i], A);
                    }else if(O==a[i]){
                        System.out.printf("%d %d 0 0 \n",O, A);
                        O=0;
                    }else if(a[i]>O){
                        System.out.println("nemoguce");
                        nemoguce=true;
                        System.exit(1);
                    }
                }
            }if(gr[i].equals("B")){
                if(a[i]<B){
                    System.out.printf("0 0 %d 0 \n", a[i]);
                    B=B-a[i];
                }else if(B==a[i]){
                    System.out.printf("0 0 %d 0 \n", B);
                    B=0;
                }else if(a[i]>B){
                    a[i]=a[1]-B;
                    if(O>a[i]){
                        O=O-a[i];
                        System.out.printf("%d %d 0 0 \n",a[i], B);
                    }else if(O==a[i]){
                        System.out.printf("%d %d 0 0 \n",O, B);
                        O=0;
                    }else if(a[i]>O){
                        System.out.println("nemoguce");
                        nemoguce=true;
                        System.exit(1);
                    }
                }
            }if(gr[i].equals("AB")){
                if(a[i]<AB){
                    System.out.printf("0 0 0 %d \n", a[i]);
                    AB=AB-a[i];
                }else if(AB==a[i]){
                    System.out.printf("0 0 0 %d \n", AB);
                    AB=0;
                }else if(a[i]>AB){
                    a[i]=a[1]-AB;
                    if(O>a[i]){
                        O=O-a[i];
                        System.out.printf("%d 0 0 %d \n",a[i], AB);
                    }else if(O==a[i]){
                        System.out.printf("%d 0 0 %d \n",O, AB);
                        O=0;
                    }else if(a[i]<O){
                        System.out.printf("%d 0 0 %d \n",O, AB);
                        a[i]=a[i]-O;
                        O=0;
                        if(a[i]<A){
                            A=A-a[i];
                            System.out.printf("%d %d 0 %d \n", O, a[i], AB);
                        }else if(a[i]==A){
                            System.out.printf("%d %d 0 %d \n", O, A, AB);
                            A=0;
                        }else if(a[i]>B){
                            if(a[i]<B){
                            B=B-a[i];
                            System.out.printf("%d %d %d %d \n", O, a[i],B, AB);
                        }else if(a[i]==B){
                            System.out.printf("%d %d %d %d \n", O, A, B, AB);
                            B=O;
                        }else if(a[i]>B){
                                System.out.println("nemoguce");
                                nemoguce=true;
                                System.exit(1);
                        }
                        }
                    }
                }
            }
        }
        
    }

}