using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split();
            int[] z = { int.Parse(s[0]), int.Parse(s[1]), int.Parse(s[2]), int.Parse(s[3])};
            int[] ab = new int[n]; int abr = 0; int[] abd = new int[n];
            int[,] d = new int[n, 4];
            for (int i = 0; i < n; i++)
            {
                s=Console.ReadLine().Split();
                int x = int.Parse(s[1]);
                if (s[0] == "O")
                {
                    if (z[0] - x > 0)
                    {
                        d[i, 0] = x;
                    }
                    if (z[0] - x < 0)
                    {
                        Console.WriteLine("nemoguce"); Environment.Exit(0);
                        break;
                        
                    }
                }
                else if (s[0] == "A")
                {
                    if (z[1] - x > 0)
                    {
                        d[i, 1] = x;
                    }
                    else
                    {
                        d[i, 1] = z[1];
                        if (z[0] - (x - z[1]) > 0)
                        {
                            d[i, 0] = x;
                        }
                        else
                        {
                            Console.WriteLine("nemoguce"); Environment.Exit(0);
                            break;
                            
                        }
                    }
                }
                else if (s[0] == "B")
                {
                    if (z[2] - x > 0)
                    {
                        d[i, 2] = x;
                    }
                    else
                    {
                        d[i, 2] = z[1];
                        if (z[0] - (x-z[1]) > 0)
                        {
                            d[i, 0] = x;
                        }
                        else
                        {
                            Console.WriteLine("nemoguce"); Environment.Exit(0);
                            break;
                        }
                    }
                }
                else if (s[0] == "AB")
                {
                    if (z[3] - x > 0)
                    {
                        d[i, 3] = x;
                    }
                    else
                    {
                        d[i, 3] = z[3];
                        ab[abr] = i;
                        abd[abr] = x-z[3];
                        abr++;
                    }
                }
            }
            for (int i = 0; i < abr; i++)
            {
                if (z[2]-abd[i]>0)
                {
                    d[ab[i], 2] = abd[i];
                }
                else if (z[1] - abd[i] > 0)
                {
                    d[ab[i], 2] = z[2];
                    d[ab[i], 1] = abd[i];
                }
                else if (z[0] - abd[i] > 0)
                {
                    d[ab[i], 2] = z[2];
                    d[ab[i], 1] = z[1];
                    d[ab[i], 0] = abd[i];
                }
            }
            Console.WriteLine("moguce");
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(d[i, 0] + " " + d[i, 1] + " " + d[i, 2] + " " + d[i, 3]);
            }
            
        }
    }
}