using System;
					
public class Program
{
	public static void Main()
	{
		Console.WriteLine("Hello World");
		            int N = int.Parse(System.Console.ReadLine());
            string[] x = new string[N];
            int[] y = new int[N];
            int i,O,A,B,AB,no,na,nb,nab;
            string[] tokens = new string[2];
            //for (i = 0; i < 4; i++)
            //{
                tokens = Console.ReadLine().Split(' ');
                O = int.Parse(tokens[0]);
                A = int.Parse(tokens[1]);
                B = int.Parse(tokens[2]);
                AB = int.Parse(tokens[3]);

            //}
            no = 0;na = 0;nb = 0;nab = 0;
            for (i = 0; i < N; i++)
            {
                tokens = Console.ReadLine().Split(' ');
                if (tokens[0] == "O")
                {
                    //no = no + 1;
                    no += int.Parse(tokens[1]);
                }
                if (tokens[0] == "A")
                {
                    na += int.Parse(tokens[1]);
                }
                if (tokens[0] == "B")
                {
                    nb += int.Parse(tokens[1]);
                }
                if (tokens[0] == "AB")
                {
                    nab += int.Parse(tokens[1]);
                }

            }
            if (na > A || na<A)
            {
                na = A;
            }
            if (nb > B || nb<B)
            {
                nb = B;
            }
            if (nab > AB || nab<AB)
            {
                nab = AB;
            }
            if (no > O || no<O)
            {
                no = O;
            }
            Console.WriteLine(no+" "+ na + " " + nb + " " + nab);
            Console.ReadLine();
	}
}