using System;

namespace _2_zdatak_kvalifikacije
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            //O A B AB
            string[] s = Console.ReadLine().Split(' ');
            int[] k = new int[4];
            k[0] = int.Parse(s[0]);
            k[1] = int.Parse(s[1]);
            k[2] = int.Parse(s[2]);
            k[3] = int.Parse(s[3]);
            int[,] p = new int[n,4];
            bool b=true;
            for (int i=0; i < n; i++)
            {
                string[] pom = Console.ReadLine().Split(' ');
                int j = int.Parse(pom[1]);
                if (pom[0] == "O")
                {
                    if (k[0] < j) { b = false; break; }
                    else { p[i, 0] = j; k[0] -= j; }
                }
                else if (pom[0] == "A" || pom[0] == "B")
                {
                    int tr;
                    if (pom[0] == "A") tr = 1;
                    else tr = 2;
                    if (k[tr] < j)
                    {
                        if (k[0] < (j - k[tr])) { b = false; break; }
                        else
                        {
                            j -= k[tr];
                            p[i, tr] = k[tr]; p[i, 0] = k[0] - j;
                            k[0] -= j;
                            k[tr] = 0;
                        }
                    }
                    else { p[i, tr] = k[tr] - j; k[tr] -= j; } 
                }
                else 
                {
                    if(k[3]<j)
                    {
                        j -= k[3];
                        int tr1, tr2;
                        if (k[1] > k[2]) { tr1 = 1; tr2 = 2; }
                        else { tr1 = 2; tr2 = 1; }
                        if (k[tr1] <= j)
                        {
                            j -= k[tr1];
                            if(k[tr2]<j)
                            {
                                j -= k[tr2];
                                if (k[0] < j) {b = false; break;  }
                                else if (j > 0) {b = false; break;  }
                                else 
                                {
                                    p[i, tr1] = k[tr1]; p[i, 0] = k[0] - j; p[i, 3] = k[3]; p[i, tr2] = k[tr2]; k[tr2] = 0; k[tr1] = 0;
                                    k[0] -= j;
                                }
                            }
                            if (k[0] < (j - k[tr1])) {b = false;  break; }
                            else 
                            {
                                k[tr1] -= j;
                                p[i, tr1] = j; p[i, 0] = k[0] - j; p[i, 3] = k[3];
                                k[0] -= j;
                            }
                        }
                        else { p[i, tr1] = k[tr1] - j; k[tr1] -= j; }
                    }
                    else
                    {
                        k[3] -= j;
                        p[i, 3] = j;
                    }
                }
            }
            if (b == false) Console.WriteLine("nemoguce");
            else
            {
                Console.WriteLine("moguce");
                for (int j = 0; j < n; j++)
                {
                    Console.Write(p[j, 0] + " " + p[j, 1] + " " + p[j, 2] + " " + p[j, 3] + '\n');
                }
            }
        }
    }
}