using System;
using System.Diagnostics;

namespace Verseny_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int O = Convert.ToInt32(Console.ReadLine());
            int A = Convert.ToInt32(Console.ReadLine());
            int B = Convert.ToInt32(Console.ReadLine());
            int AB = Convert.ToInt32(Console.ReadLine());

            int i;

            int temp;

            Adatok[] adat = new Adatok[n];
            int overallhave = O + A + B + AB;
            int overallneed = 0;
            int problems = 0;

            for (i = 0; i < n; i++)
            {
                adat[i] = new Adatok();
                adat[i].type = Console.ReadLine();
                adat[i].count = Convert.ToInt32(Console.ReadLine());
                overallneed = overallneed + adat[i].count;

            }

            int[,] arr = new int[n, 4];

            int q, w;
            for (q = 0; q < n; q++)
            {
                for (w = 0; w < 4; w++)
                {
                    arr[q, w] = 0;
                }
            }

            if (overallneed > overallhave)
            {
                Console.WriteLine("nemoguce");
            }
            else
            {
                Console.WriteLine();
                for (i = 0; i < n; i++)
                {
                    if (adat[i].type == "O") // TYPE O
                    {
                        if (O >= adat[i].count)
                        {
                            arr[i, 0] = O - adat[i].count;
                            temp = O;
                            O = O - adat[i].count;
                            adat[i].count = adat[i].count - (temp - adat[i].count);
                        }
                        else
                        {
                            problems++;
                        }
                    }

                    if (adat[i].type == "A") // TYPE A
                    {
                        if (A >= adat[i].count)
                        {
                            arr[i, 1] = A - adat[i].count;
                            temp = A;
                            A = A - adat[i].count;
                            adat[i].count = adat[i].count - (temp - adat[i].count);
                        }
                        else if (A > 0)
                        {
                            if (adat[i].count > 0)
                            {
                                arr[i, 1] = A - adat[i].count;
                                temp = A;
                                A = A - A;
                                adat[i].count = adat[i].count - (temp - adat[i].count);
                            }
                        }
                        else if (O >= adat[i].count)
                        {
                            if (adat[i].count > 0)
                            {
                                arr[i, 0] = O - adat[i].count;
                                temp = O;
                                O = O - adat[i].count;
                                adat[i].count = adat[i].count - (temp - adat[i].count);
                            }
                        }
                        else
                        {
                            problems++;
                        }
                    }

                    if (adat[i].type == "B") // TYPE B
                    {
                        if (B >= adat[i].count)
                        {
                            arr[i, 2] = B - adat[i].count;
                            temp = B;
                            B = B - adat[i].count;
                            adat[i].count = adat[i].count - (temp - adat[i].count);
                        }
                        else if (B > 0)
                        {
                            if (adat[i].count > 0)
                            {
                                arr[i, 2] = B - adat[i].count;
                                temp = B;
                                B = B - B;
                                adat[i].count = adat[i].count - (temp - adat[i].count);
                            }
                        }
                        else if (O >= adat[i].count)
                        {
                            arr[i, 0] = O - adat[i].count;
                            temp = O;
                            O = O - adat[i].count;
                            adat[i].count = adat[i].count - (temp - adat[i].count);
                        }
                        else if (O > 0)
                        {
                            if (adat[i].count > 0)
                            {
                                arr[i, 0] = O - adat[i].count;
                                temp = O;
                                O = O - O;
                                adat[i].count = adat[i].count - (temp - adat[i].count);
                            }
                        }
                        else
                        {
                            problems++;
                        }
                    }

                    if (adat[i].type == "AB") // TYPE AB
                    {
                        Console.WriteLine("AB ÉRTÉKE: "+AB);
                        Console.WriteLine("countja " + adat[i].count);
                        Console.WriteLine("0");
                        
                        if (AB >= adat[i].count)
                        {
                            Console.WriteLine("1");
                            arr[i, 3] = AB - adat[i].count;
                            temp = AB;
                            AB = AB - adat[i].count;
                            adat[i].count = adat[i].count - (temp - adat[i].count);
                        }
                        else if (AB > 0)
                        {
                            Console.WriteLine("2");
                            if (adat[i].count > 0)
                            {
                                Console.WriteLine("3");
                                arr[i, 3] = adat[i].count - AB;
                                temp = AB;
                                AB = AB - AB;
                                //arr[i, 3] = AB - adat[i].count;
                                adat[i].count = adat[i].count - AB;
                                //adat[i].count = adat[i].count - (temp - adat[i].count);
                                //adat[i].count = adat[i].count - (AB - adat[i].count);
                            }
                            Console.WriteLine("AB ÉRTÉKE: " + AB);
                            Console.WriteLine("countja " + adat[i].count);
                            Console.WriteLine(O);
                            Console.WriteLine(A);
                            Console.WriteLine(B);
                            Console.WriteLine(AB);
                        }
                        else if (A >= adat[i].count)
                        {
                            Console.WriteLine("4");
                            arr[i, 1] = A - adat[i].count;
                            temp = A;
                            A = A - adat[i].count;
                            adat[i].count = adat[i].count - (temp - adat[i].count);
                        }
                        else if (A > 0)
                        {
                            Console.WriteLine("5");
                            if (adat[i].count > 0)
                            {
                                Console.WriteLine("6");
                                arr[i, 1] = A - adat[i].count;
                                temp = A;
                                A = A - adat[i].count;
                                adat[i].count = adat[i].count - (temp - adat[i].count);
                            }
                        }
                        else if (B >= adat[i].count)
                        {
                            Console.WriteLine("7");
                            arr[i, 2] = B - adat[i].count;
                            temp = B;
                            B = B - adat[i].count;
                            adat[i].count = adat[i].count - (temp - adat[i].count);
                        }
                        else if (B > 0)
                        {
                            Console.WriteLine("8");
                            if (adat[i].count > 0)
                            {
                                Console.WriteLine("9");
                                arr[i, 2] = B - adat[i].count;
                                temp = B;
                                B = B - B;
                                adat[i].count = adat[i].count - (temp - adat[i].count);
                            }
                        }
                        else if (O >= adat[i].count)
                        {
                            Console.WriteLine("10");
                            arr[i, 0] = O - adat[i].count;
                            temp = O;
                            O = O - adat[i].count;
                            adat[i].count = adat[i].count - (temp - adat[i].count);
                        }
                        else if (O > 0)
                        {
                            Console.WriteLine("11");
                            if (adat[i].count > 0)
                            {
                                Console.WriteLine("12");
                                arr[i, 0] = O - adat[i].count;
                                temp = O;
                                O = O - O;
                                adat[i].count = adat[i].count - (temp - adat[i].count);
                            }
                        }
                        else
                        {
                            problems++;
                        }
                    }

                }
                if (problems > 0)
                {
                    Console.WriteLine("nemoguce");
                }
                else
                {
                    Console.WriteLine("moguce");
                    //for (i = 0; i < n; i++)
                    //{
                    //Console.Write(adat[i].type);
                    for (q = 0; q < n; q++)
                    {
                        for (w = 0; w < 4; w++)
                        {
                            Console.Write(arr[q, w]);
                        }
                        Console.WriteLine();
                    }
                    //}
                }
            }


            Console.ReadKey();
        }
    }

    struct Adatok
    {
        public string type;
        public int count;
    }
}