using System;

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

            string[] s = Console.ReadLine().Split();
            int o = int.Parse(s[0]);
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);
            int ab = int.Parse(s[3]);

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

            int o1 = 0;
            int a1 = 0;
            int b1 = 0;
            int ab1 = 0;

            string[] kg = new string[n];
            int[] bp = new int[n];
            int br = 0;
            string[] u;

            for (int i = 0; i < n; i++)
            {
                u = Console.ReadLine().Split();
                kg[i] = u[0];
                bp[i] = int.Parse(u[1]);
            }

            for(int i = 0; i < n; i++)
            {
                if (kg[i] == "O")
                {
                    while (bp[i] > 0 && o > 0)
                    {
                        o--;
                        o1++;
                        bp[i]--;
                    }
                    if (bp[i] > 0)
                        br++;
                }
                else if (kg[i] == "A")
                {
                    while (bp[i] > 0 && (a > 0 || o > 0))
                    { 
                        if (a > 0)
                        {
                            a--;
                            a1++;
                        }
                        else if (o > 0)
                        {
                            o--;
                            o1++;
                        }
                        bp[i]--;
                    }
                    if (bp[i] > 0)
                        br++;
                }
                else if(kg[i] == "B")
                {
                    while (bp[i] > 0 && (b > 0 || o > 0))
                    {
                        if (b > 0)
                        {
                            b--;
                            b1++;
                        }
                        else if (o > 0)
                        {
                            o--;
                            o1++;
                        }

                        bp[i]--;
                    }
                    if (bp[i] > 0)
                        br++;
                }
                pac[i, 0] = o1;
                pac[i, 1] = a1;
                pac[i, 2] = b1;
                pac[i, 3] = ab1;

                o1 = 0;
                a1 = 0;
                b1 = 0;
            }
            
            for (int i = 0; i < n; i++)
            {
                if (kg[i] == "AB")
                {
                    while (bp[i] > 0 && (b > 0 || o > 0))
                    {
                        if (ab > 0)
                        {
                            ab--;
                            ab1++;
                        }
                        else if (a > 0)
                        {
                            a--;
                            a1++;
                        }
                        else if (b > 0)
                        {
                            b--;
                            b1++;
                        }
                        else if (o > 0)
                        {
                            o--;
                            o1++;
                        }

                        bp[i]--;
                    }
                    pac[i, 0] = o1;
                    pac[i, 1] = a1;
                    pac[i, 2] = b1;
                    pac[i, 3] = ab1;

                    if (bp[i] > 0)
                        br++;
                }
            }
            

            if (br > 0)
                Console.WriteLine("nemoguce");
            else
            {
                Console.WriteLine("moguce");
                for (int i = 0; i < n; i++)
                    Console.WriteLine(pac[i, 0] + " " + pac[i, 1] + " " + pac[i, 2] + " " + pac[i, 3]);
            }

        }
    }
}