using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace transfuzija_krvi
{
    internal 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]);
            string[] kg = new string[n];
            int[] bj = new int[n];
            int[,] x = new int[n, 4];
            int p = 0;
            for (int i = 0; i < n; i++)
            {
                string[] s1 = Console.ReadLine().Split(' ');
                kg[i] = s1[0];
                bj[i] = int.Parse(s1[1]);
                if (kg[i] == "O" && o >= bj[i])
                {
                    x[i, 0] += bj[i];
                    o = o - bj[i];
                    bj[i] = 0;
                    p++;
                }
                else if (kg[i] == "O" && o < bj[i]) 
                {
                    x[i, 0] += o;
                    bj[i] = bj[i] - o;
                    o = 0;
                }
                if (kg[i] == "A" && a >= bj[i])
                {
                    x[i, 1] += bj[i];
                    a = a - bj[i];
                    bj[i] = 0;
                    p++;
                }
                else if (kg[i] == "A" && a < bj[i]) 
                {
                    x[i, 1] += a;
                    bj[i] = bj[i] - a;
                    a = 0;
                }
                if (kg[i] == "B" && b >= bj[i])
                {
                    x[i, 2] += bj[i];
                    b = b - bj[i];
                    bj[i] = 0;
                    p++;
                }
                else if (kg[i] == "B" && b < bj[i]) 
                {
                    x[i, 2] += b;
                    bj[i] = bj[i] - b;
                    b = 0;
                }
                if (kg[i] == "AB" && ab >= bj[i])
                {
                    x[i, 3] += bj[i];
                    ab = ab - bj[i];
                    bj[i] = 0;
                    p++;
                }
                else if (kg[i] == "AB" && ab < bj[i]) 
                {
                    x[i, 3] += ab;
                    bj[i] = bj[i] - ab;
                    ab = 0;
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (bj[i] != 0)
                {
                    if (kg[i] == "AB" && a >= bj[i] && bj[i] != 0) 
                    {
                        x[i, 1] += bj[i];
                        a = a - bj[i];
                        bj[i] = 0;
                        p++;
                    }
                    else if (kg[i] == "AB" && a < bj[i] && bj[i] != 0)
                    {
                        x[i, 1] += a;
                        bj[i] = bj[i] - a;
                        a = 0;
                    }
                    if (kg[i] == "AB" && b >= bj[i] && bj[i] != 0)
                    {
                        x[i, 2] += bj[i];
                        b = b - bj[i];
                        bj[i] = 0;
                        p++;
                    }
                    else if (kg[i] == "AB" && b < bj[i] && bj[i] != 0)
                    {
                        x[i, 2] += b;
                        bj[i] = bj[i] - b;
                        b = 0;
                    }
                    if ((kg[i] == "A" || kg[i] == "B" || kg[i] == "AB") && o >= bj[i] && bj[i] != 0)
                    {
                        x[i, 0] += bj[i];
                        o = o - bj[i];
                        bj[i] = 0;
                        p++;
                    }
                    else if ((kg[i] == "A" || kg[i] == "B" || kg[i] == "AB") && o < bj[i] && bj[i] != 0)
                    {
                        x[i, 0] += o;
                        bj[i] = bj[i] - o;
                        o = 0;
                    }
                }
            }
            if (p==n)
            {
                Console.WriteLine("moguce");
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        Console.Write(x[i, j] + " ");
                    }
                    Console.WriteLine();
                }
            }
            else Console.WriteLine("nemoguce");
        }
    }
}