using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int o1 = 0, a1 = 0, b1 = 0, ab1 = 0;
            string[] c = new string[10000];
            int[] d = new int[10000];
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split();
            int o = int.Parse(str[0]);
            int a = int.Parse(str[1]);
            int b = int.Parse(str[2]);
            int ab = int.Parse(str[3]);
            for (int i = 0; i < N; i++)
            {
                str = Console.ReadLine().Split();
                c[i] = str[0];
                d[i] = int.Parse(str[1]);
                if (c[i] == "O") o1 += d[i];
                else if (c[i] == "A") a1 += d[i];
                else if (c[i] == "B") b1 += d[i];
                else ab1 += d[i];
            }    
            if (o1 <= o && a1 <= a + o - o1 - Math.Abs((b - b1 - Math.Abs(b - b1)) / 2) && b1 <= b + o - o1 - Math.Abs((a - a1 - Math.Abs(a - a1)) / 2) && ab1 <= a + b + o + ab - a1 - b1 - o1)
            {
                Console.WriteLine("moguce");
                for (int i = 0; i < N; i++)
                {
                    if (c[i] == "O") Console.WriteLine("{0} 0 0 0", d[i]);
                    else if (c[i] == "A")
                    {
                        if (a >= d[i])
                        {
                            Console.WriteLine("{0} {1} 0 0", 0, d[i]);
                            a -= d[i];
                        }
                        else
                        {
                            Console.WriteLine("{0} {1} 0 0", d[i] - a, a);
                            a = 0;
                        }
                    }
                    else if (c[i] == "B")
                    {
                        if (b >= d[i])
                        {
                            Console.WriteLine("{0} 0 {1} 0", 0, d[i]);
                            b -= d[i];
                        }
                        else
                        {
                            Console.WriteLine("{0} 0 {1} 0", d[i] - b, b);
                            b = 0;
                        }
                    }
                    else
                    {
                        if (ab > d[i])
                        {
                            Console.WriteLine("0 0 0 {0}",d[i]);
                            ab -= d[i];
                        }
                        else
                        {
                            if (b > d[i] - ab)
                            {
                                Console.WriteLine("0 0 {0} {1}", d[i] - ab, ab);
                                ab = 0;
                                b -= d[i];
                            }
                            else
                            {
                                if (a > d[i] - ab - b)
                                {
                                    Console.WriteLine("0 {0} {1} {2}", d[i] - b - ab, b, ab);
                                    ab = 0;
                                    b = 0;
                                    a -= d[i];
                                }
                                else
                                {
                                    Console.WriteLine("{0} {1} {2} {3}", d[i] - a - b - ab, a, b, ab);
                                    ab = 0;
                                    b = 0;
                                    a = 0;
                                }
                            }
                        }
                    } 
                        
                }
            }
            else Console.WriteLine("nemoguce");
        }
    }
}