using System;

namespace Takmicenja
{
    class Program
    {
        static void rad(int o, int a, int b, int ab, string[] p, int n, int[] r, int[,] x, int i, ref int t)
        {
            if (p[i] == "O")
            {
                if(r[i] <= o)
                {
                    x[0, i] = r[i];
                }
                else
                {
                    t++;
                    Console.WriteLine("nemoguce");
                    return;
                }
            }
            if (p[i] == "A")
            {
                if (r[i] <= a)
                {
                    x[1, i] = r[i];
                }
                else
                {
                    r[i] -= a;
                    if (r[i] > 0)
                    {
                        x[1, i] = a;
                        x[0, i] = r[i];
                    }
                }
            }
            if (p[i] == "B")
            {
                if (r[i] <= b)
                {
                    x[2, i] = r[i];
                }
                else
                {
                    r[i] -= b;
                    if (r[i] > 0)
                    {
                        x[2, i] = b;
                        x[0, i] = r[i];
                    }
                }
            }
            if (p[i] == "AB")
            {
                if(r[i] <= ab)
                {
                    x[3, i] = r[i];
                }
                else
                {
                    r[i] -= ab;
                    if (r[i] > 0)
                    {
                        x[3, i] = ab;
                        if (r[i] <= b)
                        {
                            x[2, i] = r[i];
                        }
                        else
                        {
                            r[i] -= b;
                            if (r[i] > 0)
                            {
                                x[2, i] = b;
                                if (r[i] <= a)
                                {
                                    x[1, i] = r[i];
                                }
                                else
                                {
                                    r[i] -= a;
                                    if (r[i] > 0)
                                    {
                                        x[1, i] = a;
                                        x[0, i] = r[i];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            for (int j = 0; j < n; j++)
            {
                if (x[j, i] < 0)
                {
                    t++;
                    Console.WriteLine("nemoguce");
                    return;
                }
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] p = new string[n];
            int[] r = new int[n];
            string[] c = Console.ReadLine().Split();
            int o = int.Parse(c[0]);
            int a = int.Parse(c[1]);
            int b = int.Parse(c[2]);
            int ab = int.Parse(c[3]);
            int t = 0;
            int[,] x = new int[4, n];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split();
                p[i] = s[0];
                r[i] = int.Parse(s[1]);
                int k = r[i];
                rad(o, a, b, ab, p, n, r, x, i, ref t);
                o -= x[0, i];
                a -= x[1, i];
                b -= x[2, i];
                ab -= x[3, i];
            }
            if (t == 0)
            {
                Console.WriteLine("moguce");
                for (int j = 0; j < n; j++)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        Console.Write(x[i, j] + " ");
                    }
                    Console.WriteLine();
                }
            }
        }
    }
}