using System;

namespace _2
{
    class Program
    {
        static void Citaj(string[] c, int[] x, int n)
        {
            for(int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split();
                c[i] = s[0];
                x[i] = int.Parse(s[1]);
            }
        }
        static void Pisi(int[,] x, int n)
        {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 4; j++)
                {
                    Console.Write(x[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split();
            int o = int.Parse(s[0]), a = int.Parse(s[1]), b = int.Parse(s[2]), ab = int.Parse(s[3]), m = 0;
            string[] c = new string[n];
            int[] x = new int[n];
            int[,] y = new int[n, 4];
            Citaj(c, x, n);
            for(int i = 0; i < n; i++)
            {
                if (c[i] == "O")
                {
                    if (x[i] <= o)
                    {
                        y[i, 0] = x[i];
                        o -= x[i];
                    }
                    else
                    {
                        Console.WriteLine("nemoguce");
                        m = 1;
                        break;
                    }
                    
                }
                else if (c[i] == "A")
                {
                    if (x[i] <= a)
                    {
                        y[i, 1] = a;
                        a -= x[i];
                    }
                    else if(x[i]<=a+o)
                    {
                        x[i] -= a;
                        o -= x[i];
                        y[i, 1] = a;
                        a = 0;
                        y[i, 0] = x[i];
                    }
                    else
                    {
                        Console.WriteLine("nemoguce");
                        m = 1;
                        break;
                    }
                }
                else if (c[i] == "B")
                {
                    if (x[i] <= b)
                    {
                        y[i, 2] = x[i];
                        b -= x[i];
                    }
                    else if (x[i] <= b + o)
                    {
                        x[i] -= b;
                        o -= x[i];
                        y[i, 2] = b;
                        b = 0;
                        y[i, 0] = x[i];
                    }
                    else
                    {
                        Console.WriteLine("nemoguce");
                        m = 1;
                        break;
                    }
                }
                else
                {
                    if (x[i] <= ab)
                    {
                        y[i, 3] = x[i];
                        ab -= x[i];
                    }
                    else if (x[i] <= ab + b + o + a)
                    {
                        x[i] -= ab;
                        y[i, 3] = ab;
                        ab = 0;
                        if (o >= x[i])
                        {
                            y[i, 0] = x[i];
                            o -= x[i];
                            break;
                        }
                        else
                        {
                            x[i] -= o;
                            y[i, 0] = o;
                            o = 0;
                        }
                        if (a >= x[i])
                        {
                            y[i, 1] = x[i];
                            a -= x[i];
                            break;
                        }
                        else
                        {
                            x[i] -= a;
                            y[i, 1] = a;
                            a = 0;
                        }
                        if (b >= x[i])
                        {
                            y[i, 2] = x[i];
                            b -= x[i];
                            break;
                        }
                        else
                        {
                            x[i] -= b;
                            y[i, 2] = b;
                            b = 0;
                        }
                    }
                    else
                    {
                        Console.WriteLine("nemoguce");
                        m = 1;
                        break;
                    }
                }

            }
            if (m == 0)
            {
                Console.WriteLine("moguce");
                Pisi(y, n);
            }
        }
    }
}