using System;

namespace Zadatak2_Transfuzija_Krvi
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, Oz, O = 0, Os, Az, A = 0, As, Bz, B = 0, Bs, ABz, AB = 0, ABs, i, k=0, l=0, a, b, c, d;
            n = Convert.ToInt32(Console.ReadLine());
            string[] tip = new string[n];
            int[] x = new int[n];
            Oz = Convert.ToInt32(Console.ReadLine());
            Az = Convert.ToInt32(Console.ReadLine());
            Bz = Convert.ToInt32(Console.ReadLine());
            ABz = Convert.ToInt32(Console.ReadLine());
            for (i = 0; i < n; i++)
            {
                tip[i] = Console.ReadLine();
                x[i] = Convert.ToInt32(Console.ReadLine());
                switch (tip[i])
                {
                    case "O":
                        O = O + x[i];
                        break;

                    case "A":
                        A = A + x[i];
                        break;

                    case "B":
                        B = B + x[i];
                        break;

                    case "AB":
                        AB = AB + x[i];
                        break;
                }
            }
            Os = Oz - O;
            int Ow = Os;
            As = Az - A;
            Bs = Bz - B;
            ABs = ABz - AB;
            if (Ow > 0)
            {
                if (As < 0)
                {
                    Ow = Ow + As;
                }
                else
                {
                    l = l + As;
                }
                if (Bs < 0)
                {
                    Ow = Ow + Bs;
                }
                else
                {
                    l = l + Bs;
                }
                if (ABs < 0)
                {
                    ABs = ABs + l;
                    if (ABs < 0)
                    {
                        Ow = Ow + ABs;
                    }
                }
                if (Ow < 0)
                {
                    k = 1;
                }
            }
            else
            {
                k = 1;
            }
            if (k == 0)
            {
                Console.WriteLine("moguce");
                for (i = 0; i < n; i++)
                {
                    a = 0;
                    b = 0;
                    c = 0;
                    d = 0;
                    switch (tip[i])
                    {
                        case "O":
                            Oz = Oz - x[i];
                            a = x[i];
                            break;

                        case "A":
                            Az = Az - x[i];
                            if (Az < 0)
                            {
                                Oz = Oz + Az;
                                a = Math.Abs(Az);
                                b = x[i] - a;
                                Az = 0;
                            }
                            else
                            {
                                b = x[i];
                            }
                            break;
                            

                        case "B":
                            Bz = Bz - x[i];
                            if (Bz < 0)
                            {
                                Oz = Oz + Bz;
                                a = Math.Abs(Bz);
                                c = x[i] - a;
                                Bz = 0;
                            }
                            else
                            {
                                c = x[i];
                            }
                            break;

                        case "AB":
                            ABz = ABz - x[i];
                            if (ABz < 0)
                            {
                                d = x[i] + ABz;
                                if (As > 0)
                                {
                                    ABz = ABz + As;
                                    if (ABz > 0)
                                    {
                                        b = As - ABz;
                                        As = ABz;
                                    }
                                    else
                                    {
                                        b = As;
                                        As = 0;
                                    }
                                }
                                if(ABz < 0)
                                {
                                    if (Bs > 0)
                                    {
                                        ABz = ABz + Bs;
                                        if (ABz > 0)
                                        {
                                            c = Bs - ABz;
                                            Bs = ABz;
                                        }
                                        else
                                        {
                                            c = Bs;
                                            Bs = 0;
                                        }
                                    }
                                }
                                if (ABz < 0)
                                {
                                    Oz = Oz + ABz;
                                    a = Math.Abs(ABz);
                                }
                                
                            }
                            else
                            {
                                d = x[i];
                            }
                            break;
                    }
                    Console.WriteLine("{0} {1} {2} {3}", a, b, c, d);
                }
            }
            else
            {
                Console.WriteLine("nemoguce");
            }

        }
    }
}