using System;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] st = new int[4];
            string[] st1 = Console.ReadLine().Split();
            st[0] = Convert.ToInt32(st1[0]);
            st[1] = Convert.ToInt32(st1[1]);
            st[2] = Convert.ToInt32(st1[2]);
            st[3] = Convert.ToInt32(st1[3]);
            int[] brk = new int[n];
            int[,] m = new int[n, 4];
            string[] ik = new string[n];
            string[] g = { "O", "A", "B", "AB" };
            int r = 0;
            int p = 0;
            for (int i = 0; i < n; i++)
            {
                string[] u = Console.ReadLine().Split();
                ik[i] = u[0];
                brk[i] = Convert.ToInt32(u[1]);
            }
            for (int i = 0; i < n; i++)
            {
                int k = Array.IndexOf(g, ik[i]);
                int c = k;
                while (brk[i] > 0)
                {
                    m[i, k] = m[i, k] + Math.Min(st[k], brk[i]);
                    st[k] -= m[i, k];
                    brk[i] -= m[i, k];
                    if (st[k] == 0 && c == 3)
                    {
                        if (k == 0)
                        {
                            r = 1;
                            break;
                        }
                        k--;
                    }
                    if (st[k] == 0 && c!=3)
                    {
                        if (k == 0)
                        {
                            r = 1;
                            break;
                        }
                        k=0;
                    }
                }
                if (r == 1)
                {
                    break;
                }
            }
            if (r == 1)
            {
                Console.WriteLine("nemoguce");
            }
            if (r == 0)
            {
                Console.WriteLine("moguce");
                for (int i = 0; i < n; i++)
                {
                    Console.WriteLine(m[i, 0] + " " + m[i, 1] + " " + m[i, 2] + " " + m[i, 3]);
                }
            }
        }
    }
}