using System;

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

            int O;
            int A;
            int B;
            int AB;

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

            int i;
            Adatok[] adatok = new Adatok[n];
            for (i=0; i<n; i++)
            {
                adatok[i] = new Adatok();
                adatok[i].type = Console.ReadLine();
                adatok[i].count = Convert.ToInt32(Console.ReadLine());
            }
            int problem=0;

            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;
                }
            }

            for (i = 0; i < n; i++)
            {
                if (adatok[i].type == "O")
                {
                    if (O >= adatok[i].count)
                    {
                        arr[i, 3] = O;
                        //arr[i, 3] = O-adatok[i].count;
                        adatok[i].count = 0;
                        O = O - adatok[i].count;
                    }
                    else
                    {
                        problem++;
                    }
                }

                if (adatok[i].type == "A")
                {
                    if (A >= adatok[i].count)
                    {
                        arr[i, 1] = A - adatok[i].count;
                        adatok[i].count = 0;
                        A = A - adatok[i].count;
                    }
                    else if(A>0)
                    {
                        arr[i, 1] = A;
                        adatok[i].count = adatok[i].count - A;
                        A = 0;
                    }
                    else if(O>= adatok[i].count)
                    {
                        Console.WriteLine();
                        Console.WriteLine(O);
                        Console.WriteLine(adatok[i].count);
                        Console.WriteLine();

                        arr[i, 0] = O - adatok[i].count;
                        O -= adatok[i].count;
                        adatok[i].count = 0;

                        Console.WriteLine();
                        Console.WriteLine(O);
                        Console.WriteLine(adatok[i].count);
                        Console.WriteLine();
                    }
                    if (adatok[i].count > 0)
                    {
                        if (O > 0)
                        {
                            arr[i, 0] = O;
                            adatok[i].count = adatok[i].count - O;
                            O = 0;
                        }
                    }
                }

                if (adatok[i].type == "B")
                {
                    if (B>=adatok[i].count)
                    {
                        arr[i, 2] = B - adatok[i].count;
                        B = B - adatok[i].count;
                        adatok[i].count = 0;
                    }
                    else if (B > 0)
                    {
                        arr[i, 2] = B;
                        adatok[i].count = adatok[i].count - B;
                        B = 0;
                    }
                    else if (O >= adatok[i].count)
                    {
                        arr[i, 0] = O - adatok[i].count;
                        O = O - adatok[i].count;
                        adatok[i].count = 0;
                    }
                    if (adatok[i].count > 0)
                    {
                        if (O > 0)
                        {
                            arr[i, 0] = O;
                            adatok[i].count = adatok[i].count - O;
                            O = 0;
                        }
                    }
                }

                if (adatok[i].type == "AB")
                {
                    if (AB >= adatok[i].count)
                    {
                        arr[i, 3] = AB - adatok[i].count;
                        AB = AB - adatok[i].count;
                        adatok[i].count = 0;
                    }
                    else if (AB > 0)
                    {
                        arr[i, 3] = AB;
                        adatok[i].count = adatok[i].count - AB;
                        AB = 0;
                    }
                    else if (A >= adatok[i].count)
                    {
                        arr[i, 1] = A - adatok[i].count;
                        A = A - adatok[i].count;
                        adatok[i].count = 0;
                    }
                    else if (A > 0)
                    {
                        arr[i, 1] = A;
                        adatok[i].count = adatok[i].count - A;
                        A = 0;
                    }
                    else if (B >= adatok[i].count)
                    {
                        arr[i, 2] = B - adatok[i].count;
                        B = B - adatok[i].count;
                        adatok[i].count = 0;
                    }
                    else if (B > 0)
                    {
                        arr[i, 2] = B;
                        adatok[i].count = adatok[i].count - B;
                        B = 0;
                    }
                    else if (O >= adatok[i].count)
                    {
                        arr[i, 0] = O - adatok[i].count;
                        O = O - adatok[i].count;
                        adatok[i].count = 0;
                    }
                    if (adatok[i].count > 0)
                    {
                        if (O > 0)
                        {
                            arr[i, 0] = O;
                            adatok[i].count = adatok[i].count - O;
                            O = 0;
                        }
                    }
                }
                if (adatok[i].count>0)
                {
                    problem++;
                }
            }
            if (problem > 0)
            {
                Console.WriteLine("nemoguce");
            }
            else
            {
                Console.WriteLine("moguce");
                for (q=0; q<n; q++)
                {
                    for (w=0; w<4; w++)
                    {
                        Console.Write(arr[q, w]);
                    }
                    Console.WriteLine();
                }
            }
        }
    }

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