using System;

namespace Zadatak2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] st = Console.ReadLine().Split(' ');
            int o = int.Parse(st[0]);
            int a = int.Parse(st[1]);
            int b = int.Parse(st[2]);
            int ab = int.Parse(st[3]);
            int u = 1;
            int[,] x;
            x = new int[n, 4];
            string[] k;
            k = new string[n];
            int[] br;
            br = new int[n];
            for (int i=0;i<n;i++)
            {
                string[] sts = Console.ReadLine().Split(' ');
                k[i] = sts[0];
                br[i] = int.Parse(sts[1]);
            }
            for (int i = 0; i < n && u != 0; i++)
            {
                if ("O" == k[i])
                {
                    int p = br[i];
                    int j = 0;
                    if (o - p < 0) u = 0;
                    else
                    {
                        for (j = 0; j < p && o != 0; j++)
                        {
                            o--;
                            x[i, 0]++;
                        }
                    }
                }
                if ("A" == k[i])
                {
                    int p = br[i];
                    int j = 0;
                    if (a + o - p < 0) u = 0;
                    else
                    {
                        for (j = 0; j < p && a != 0; j++)
                        {
                            a--;
                            x[i, 1]++;
                        }
                        for (; j < p && o != 0; j++)
                        {
                            o--;
                            x[i, 0]++;
                        }
                    }
                }
                if ("B" == k[i])
                {
                    int p = br[i];
                    int j = 0;
                    if (b + o - p < 0) u = 0;
                    else
                    {
                        for (j = 0; j < p && b != 0; j++)
                        {
                            b--;
                            x[i, 2]++;
                        }
                        for (; j < p && o != 0; j++)
                        {
                            o--;
                            x[i, 0]++;
                        }
                    }
                }
            }
                for (int i=0;i<n && u!=0;i++)
                {
                if ("AB" == k[i])
                {
                    int p = br[i];
                    int j = 0;
                    if (b+o+a+ab - p < 0) u = 0;
                    else
                    {
                        for (j = 0; j < p && ab != 0; j++)
                        {
                            ab--;
                            x[i, 3]++;
                        }
                        for (; j < p && (a != 0 || b!=0); j++)
                        {
                            if(a>b)
                            {
                                a--;
                                x[i, 1]++;
                            }
                            else
                            {
                                b--;
                                x[i, 2]++;
                            }
                        }
                        for (; j < p && o != 0; j++)
                        {
                            o--;
                            x[i, 0]++;
                        }
                    }
                }
                }
            if (u == 0) Console.Write("nemoguce");
            else
            {
                Console.Write("moguce");
                for(int i=0;i<n;i++)
                {
                    Console.WriteLine();
                    for(int j=0;j<4;j++)
                    {
                        Console.Write("{0} ", x[i, j]);
                    }
                }
            }
        }
    }
}