package takmicenjedrugi;

import java.util.Scanner;

public class TakmicenjeDrugi {

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