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

namespace Tranfuzija_krvi
{
    class Program
    {
        static void Main(string[] args)
        {
            
            bool p = true;
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split();
            int[] a =   { int.Parse(s[0]),
                          int.Parse(s[1]),
                          int.Parse(s[2]),
                          int.Parse(s[3])
                         };
            int b = 0;
            int[,] resenje = new int[n, 4];
            List<int> L = new List<int>();
            List<int> L1 = new List<int>();
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split();
                string c = s[0];
                int k = int.Parse(s[1]);
                if (p)
                {
                    switch (c)
                    {
                        case "O":
                            {
                                a[0] -= k;
                                resenje[i,0] = k;
                                if (a[0] < 0) p = false;
                                break;
                            }
                        case "A":
                            {
                                if (k - a[1] <= 0)
                                {
                                    a[1] -= k;
                                    resenje[i, 1] = k;
                                }
                                else if (k - a[1] - a[0] <= 0)
                                {
                                    a[0] -= k - a[1];
                                    resenje[i, 1] = a[1];
                                    resenje[i, 0] = k - a[1];
                                    a[1] = 0;
                                }
                                else p = false;
                                break;
                            }
                        case "B":
                            {
                                if (k - a[2] <= 0)
                                {
                                    a[2] -= k;
                                    resenje[i, 2] = k;
                                }
                                else if (k - a[2] - a[0] <= 0)
                                {
                                    a[0] -= k - a[2];
                                    resenje[i, 2] = a[2];
                                    resenje[i, 0] = k - a[2];
                                    a[2] = 0;
                                }
                                else p = false;
                                break;
                            }
                        case "AB":
                            {
                                b += k;
                                L.Add(i);
                                L1.Add(k);
                                break;
                            }
                        default:
                            break;
                    }
                }
            }
            if (!p) Console.WriteLine("nemoguce");
            else
            {
                if (a[0] + a[1] + a[2] + a[3] < b) Console.WriteLine("nemoguce");
                else
                {
                    int f = 0;
                    Console.WriteLine("moguce");
                    for (int i = 0; i < n; i++)
                    {
                        if(L.Contains(i))
                        {
                            int m = L1[f];
                            if (m - a[3] <= 0)
                            {
                                a[3] -= m;
                                resenje[i, 3] = m;
                            }
                            else
                            {
                                m -= a[3];
                                resenje[i, 3] = a[3];
                                a[3] = 0;
                                if(m-a[2]<=0)
                                {
                                    a[2] -= m;
                                    resenje[i, 2] = m;
                                }
                                else
                                {
                                    m -= a[2];
                                    resenje[i, 2] = a[2];
                                    a[2] = 0;
                                    if(m-a[1]<=0)
                                    {
                                        a[1] -= m;
                                        resenje[i, 1] = m;
                                    }
                                    else
                                    {
                                        m -= a[1];
                                        resenje[i, 1] = a[1];
                                        a[1] = 0;
                                        resenje[i, 0] = m;
                                        a[0] -= m;
                                    }
                                }
                            }
                            Console.WriteLine(resenje[i, 0] + " " + resenje[i, 1] + " " + resenje[i, 2] + " " + resenje[i, 3]);
                            f++;
                        }
                        else Console.WriteLine(resenje[i, 0] + " " + resenje[i, 1] + " " + resenje[i, 2] + " " + resenje[i, 3]);
                    }
                }
            }
        }
    }
}