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

namespace Transfuzija_krvi
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] line = Console.ReadLine().Split();
            int brUkJedinicaO = int.Parse(line[0]);
            int brUkJedinicaA = int.Parse(line[1]);
            int brUkJedinicaB = int.Parse(line[2]);
            int brUkJedinicaAB = int.Parse(line[3]);
            int brOstO = brUkJedinicaO;
            int brOstA = brUkJedinicaA;
            int brOstB = brUkJedinicaB;
            int brOstAB = brUkJedinicaAB;
            int brO = 0;
            int brA = 0;
            int brB = 0;
            int brAB = 0;
            int novibrOstO = brUkJedinicaO;
            int novibrOstA = brUkJedinicaA;
            int novibrOstB = brUkJedinicaB;
            int novibrOstAB = brUkJedinicaAB;
            string s;
            string rezultat = "moguce";
            string rezultatBrojevi = "";
            for (int i = 0; i < n; i++)
            {
                brO = 0;
                brA = 0;
                brB = 0;
                brAB = 0;
                s = Console.ReadLine();
                string[] s2 = s.Split();
                if (s2[0] == "O") brO += Convert.ToInt32(s2[1]);
                if (s2[0] == "A") brA += Convert.ToInt32(s2[1]);
                if (s2[0] == "B") brB += Convert.ToInt32(s2[1]);
                if (s2[0] == "AB") brAB += Convert.ToInt32(s2[1]);
                brOstO -= brO;
                brOstA -= brA;
                brOstB -= brB;
                brOstAB -= brAB;
                while (brOstA < 0 && brOstO > 0)
                {
                    brOstA++;
                    brOstO--;
                }
                while (brOstB < 0 && brOstO > 0)
                {
                    brOstB++;
                    brOstO--;
                }
                while (brOstAB < 0 && brOstO > 0)
                {
                    brOstAB++;
                    brOstO--;
                }
                while (brOstAB < 0 && brOstA > 0)
                {
                    brOstAB++;
                    brOstA--;
                }
                while (brOstAB < 0 && brOstB > 0)
                {
                    brOstAB++;
                    brOstB--;
                }
                rezultatBrojevi += (novibrOstO - brOstO) + " " + (novibrOstA - brOstA) + " " + (novibrOstB - brOstB) + " " + (novibrOstAB - brOstAB) + "\n";
                novibrOstO = brOstO;
                novibrOstA = brOstA;
                novibrOstB = brOstB;
                novibrOstAB = brOstAB;
                if (brOstO < 0 || brOstA < 0 || brOstB < 0 || brOstAB < 0) rezultat = "nemoguce";
            }
            Console.WriteLine(rezultat);
            if (rezultat == "moguce") Console.WriteLine(rezultatBrojevi.Trim());
        }
    }
}