import java.util.Scanner;

public class Zad2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), o = in.nextInt(), a = in.nextInt(), b = in.nextInt(), ab = in.nextInt();
        String g[] = new String[n];
        int j[] = new int[n], br = 0;
        int m[][] = new int[n][4];
        for (int i = 0; i < n; i++) {
            g[i] = in.next();
            j[i] = in.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (g[i].equals("O")) {
                for (int k = 0; k < j[i]; k++) {
                    if (o > 0) {
                        o -= 1;
                        m[i][0] += 1;
                    } else {
                        br++;
                    }
                }
            } else if (g[i].equals("A")) {
                for (int k = 0; k < j[i]; k++) {
                    if (a > 0) {
                        a -= 1;
                        m[i][1] += 1;
                    } else if (o > 0) {
                        o -= 1;
                        m[i][0] += 1;
                    } else {
                        br++;
                    }
                }
            } else if (g[i].equals("B")) {
                for (int k = 0; k < j[i]; k++) {
                    if (b > 0) {
                        b -= 1;
                        m[i][2] += 1;
                    } else if (o > 0) {
                        o -= 1;
                        m[i][0] += 1;
                    } else {
                        br++;
                    }
                }
            } else if (g[i].equals("AB")) {
                for (int k = 0; k < j[i]; k++) {
                    if (ab > 0) {
                        ab -= 1;
                        m[i][3] += 1;
                    } else if (o > 0) {
                        o -= 1;
                        m[i][0] += 1;
                    } else if (a > 0) {
                        a -= 1;
                        m[i][1] += 1;
                    } else if (b > 0) {
                        b -= 1;
                        m[i][2] += 1;
                    } else {
                        br++;
                    }
                }
            }
        }
        if (br == 0) {
            System.out.println("moguce");
            for (int i = 0; i < n; i++) {
                for (int p = 0; p < 4; p++) {
                    System.out.print(m[i][p] + " ");
                }
                System.out.println();
            }
        } else {
            System.out.println("nemoguce");
        }
    }

}