using System;

namespace jej
{
    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]);
            bool moguce = true;
            int[,] x = new int[n, 4];
            string[] kg = new string[n];
            int[] br = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] st = Console.ReadLine().Split();
                kg[i] = st[0];
                br[i] = int.Parse(st[1]);
            }
            for (int i = 0; i < n; i++)
            {
                int o1 = 0, a1 = 0, b1 = 0, ab1 = 0;
                if (kg[i] == "A")
                {
                    if (a - br[i] >= 0)
                    {
                        a -= br[i];
                        a1 += br[i];
                    }
                    else
                    {
                        a1 += a;
                        br[i] -= a;
                        a = 0;
                        if (o - br[i] >= 0)
                        {
                            o -= br[i];
                            o1 += br[i];
                        }
                        else
                        {
                            moguce = false;
                        }
                    }
                }
                else if (kg[i] == "B")
                {
                    if (b - br[i] >= 0)
                    {
                        b -= br[i];
                        b1 += br[i];
                    }
                    else
                    {
                        b1 += b;
                        br[i] -= b;
                        b = 0;
                        if (o - br[i] >= 0)
                        {
                            o -= br[i];
                            o1 += br[i];
                        }
                        else
                        {
                            moguce = false;
                        }
                    }
                }
                if (moguce && (kg[i] == "A" || kg[i] == "B")) 
                {
                    x[i, 0] = o1;
                    x[i, 1] = a1;
                    x[i, 2] = b1;
                    x[i, 3] = ab1;
                }
            }

            for (int i = 0; i < n; i++)
            {
                int o1 = 0, a1 = 0, b1 = 0, ab1 = 0;
                if (kg[i] == "O")
                {
                    if (o - br[i] >= 0)
                    {
                        o -= br[i];
                        o1 += br[i];
                    }
                    else
                    {
                        moguce = false;
                    }
                }
                else if (kg[i] == "AB") 
                {
                    if (ab - br[i] >= 0)
                    {
                        ab -= br[i];
                        ab1 += br[i];
                    }
                    else
                    {
                        ab1 += ab;
                        br[i] -= ab;
                        ab = 0;
                        if (a - br[i] >= 0)
                        {
                            a -= br[i];
                            a1 += br[i];
                        }
                        else
                        {
                            a1 += a;
                            br[i] -= a;
                            a = 0;
                            if (b - br[i] >= 0)
                            {
                                b -= br[i];
                                b1 += br[i];
                            }
                            else
                            {
                                b1 += b;
                                br[i] -= b;
                                b = 0;
                                if (o - br[i] >= 0)
                                {
                                    o -= br[i];
                                    o1 += br[i];
                                }
                                else
                                {
                                    moguce = false;
                                }
                            }
                        }
                    }
                }
                if (moguce && (kg[i] == "O" || kg[i] == "AB"))
                {
                    x[i, 0] = o1;
                    x[i, 1] = a1;
                    x[i, 2] = b1;
                    x[i, 3] = ab1;
                }
            }
            if (moguce)
            {
                Console.WriteLine("moguce");
                for (int i = 0; i < n && moguce; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        Console.Write(x[i, j] + " ");
                    }
                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("nemoguce");
            }
        }
    }
}