using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.SymbolStore;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net.WebSockets;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Schema;
using System.Numerics;
//using System.Data;
//using System.Drawing;

namespace ConsoleApp3
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Split();
            int o = int.Parse(s[0]);
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);
            int ab = int.Parse(s[3]);
            List<int> posO = new List<int>();
            List<int> posA = new List<int>();
            List<int> posB = new List<int>();
            List<int> posAB = new List<int>();
            List<Tuple<int, Tuple<int, int, int, int>>> res = new List<Tuple<int, Tuple<int, int, int, int>>>();
            long zb = 0;
            for (int i=0;i<n;i++)
            {
                s = Console.ReadLine().Split();
                string key = s[0];
                int val = int.Parse(s[1]);
                zb += val;
                res.Add(Tuple.Create(val, Tuple.Create(0, 0, 0, 0)));
                if (key == "O")
                    posO.Add(i);
                else if (key == "A")
                    posA.Add(i);
                else if (key == "B")
                    posB.Add(i);
                else if (key == "AB")
                    posAB.Add(i);
            }
            if(zb>(o+a+b+ab))
            {
                Console.WriteLine("nemoguce");
                return;
            }
            for(int i=0;i<posO.Count;i++)
            {
                int pos = posO[i];
                int value = res[pos].Item1;
                if(o>=value)
                {
                    o -= value;
                    res[pos] = Tuple.Create(value, Tuple.Create(value, 0, 0, 0));
                }
                else
                {
                    Console.WriteLine("nemoguce");
                    return;
                }
            }
            for (int i = 0; i < posA.Count; i++)
            {
                int pos = posA[i];
                int value = res[pos].Item1;
                if ((o+a) >= value)
                {
                    int o1 = 0;
                    int a1 = 0;
                    if(o>=value)
                    {
                        o -= value;
                        o1 = value;
                    }
                    else if(o<value)
                    {
                        o1 += o;
                        value -= o;
                        a1 += value;
                        a -= value;
                    }
                    res[pos] = Tuple.Create(value, Tuple.Create(o1, a1, 0, 0));
                }
                else
                {
                    Console.WriteLine("nemoguce");
                    return;
                }
            }
            for (int i = 0; i < posB.Count; i++)
            {
                int pos = posB[i];
                int value = res[pos].Item1;
                if ((o + b) >= value)
                {
                    int o1 = 0;
                    int b1 = 0;
                    if (o >= value)
                    {
                        o -= value;
                        o1 = value;
                    }
                    else if (o < value)
                    {
                        o1 += o;
                        value -= o;
                        o = 0;
                        b1 += value;
                        b -= value;
                    }
                    res[pos] = Tuple.Create(value, Tuple.Create(o1, 0, b1, 0));
                }
                else
                {
                    Console.WriteLine("nemoguce");
                    return;
                }
            }
            for (int i = 0; i < posAB.Count; i++)
            {
                int pos = posAB[i];
                int value = res[pos].Item1;
                if ((o + b + ab + a) >= value)
                {
                    int o1 = 0;
                    int a1 = 0;
                    int b1 = 0;
                    int ab1 = 0;
                    if(o>=value)
                    {
                        o -= value;
                        o1 += value;
                    }
                    else
                    {
                        o1 += o;
                        value -= o;
                        if(a>=value)
                        {
                            a1 += value;
                            a -= value;
                        }
                        else
                        {
                            a1 += a;
                            value -= a;
                            a = 0;
                            if(b>=value)
                            {
                                b1 += value;
                                b -= value;
                            }
                            else
                            {
                                b1 += b;
                                value -= b;
                                b = 0;
                                if(ab>=value)
                                {
                                    ab1 += value;
                                    ab -= value;
                                }                        
                            }
                        }
                    }
                    res[pos] = Tuple.Create(value, Tuple.Create(o1, a1, b1, ab1));
                }
                else
                {
                    Console.WriteLine("nemoguce");
                    return;
                }
            }
            Console.WriteLine("moguce");
            for(int i=0;i<res.Count;i++)
            {
                var tuple = res[i].Item2;
                Console.WriteLine(tuple.Item1+" "+tuple.Item2+" "+tuple.Item3+" "+tuple.Item4);
            }
        }
    }
}