/******************************************************************************

                            Online C# Compiler.
                Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

using System;
class pacijent
{
    public int grupa;
    public int br_doza;
}
class program {
  static void Main() 
  {
    int N = int.Parse(Console.ReadLine());
    int[] a = new int[4];
    string[] s = Console.ReadLine().Split();
    for (int i = 0; i < 4; i++)
        a[i] = int.Parse(s[i]);
    pacijent[] p = new pacijent[N];
    for(int i = 0; i < N; i++)
    {
        s = Console.ReadLine().Split();
        pacijent x = new pacijent();
        x.grupa = 3;
        if (s[0] == "O")
        x.grupa = 0;
        else if (s[0] == "A")
        x.grupa = 1;
        else if (s[0] == "B")
        x.grupa = 2;
        x.br_doza = int.Parse(s[1]);
        p[i] = x;
    }
    int[,] m = new int[N,4];
    bool da = true;
    for (int i = 0; i < N; i++)
    {
        if (p[i].grupa == 0)
        {
        if (a[0] >= p[i].br_doza)
        {
            a[0] -= p[i].br_doza;
            m[i, 0] = p[i].br_doza;
        }
        else
        {
            da = false;
            break;
        }
        }
        else if (p[i].grupa == 1)
        {
        if (a[0] + a[1] >= p[i].br_doza)
        {
            if (a[1] > p[i].br_doza)
            {
                m[i, 1] = p[i].br_doza;
            a[1] -= p[i].br_doza;
            }
            else
            {
                m[i, 0] = p[i].br_doza - a[1];
                m[i, 1] = a[1];
                a[0] = a[0] - p[i].br_doza + a[1];
                a[1] = 0;
            }
        }
        else
        {
            da = false;
            break;
        }
        }
        else if (p[i].grupa == 2)
        {
        if (a[0] + a[2] >= p[i].br_doza)
        {
            if (a[2] > p[i].br_doza)
            {
                m[i, 2] = p[i].br_doza;
            a[2] -= p[i].br_doza;
            }
            else
            {
                m[i, 0] = p[i].br_doza - a[2];
                m[i, 2] = a[2];
                a[0] = a[0] - p[i].br_doza + a[2];
                a[2] = 0;
            }
        }
        else
        {
            da = false;
            break;
        }
        }
        else
        {
            if (a[0] + a[1] + a[2] + a[3] >= p[i].br_doza)
            {
                if (a[3] >= p[i].br_doza)
                {
                    m[i, 3] = p[i].br_doza;
                    a[3] -= p[i].br_doza;
                }
                else if (a[0] + a[3] >= p[i].br_doza)
                {
                    m[i, 0] = p[i].br_doza - a[3];
                    m[i, 3] = a[3];
                    a[3] = 0;
                    a[0] = a[0] - p[i].br_doza + a[3];
                }
                else if (a[0] + a[1] + a[3] >= p[i].br_doza)
                {
                    m[i, 1] = p[i].br_doza - a[2] - a[3];
                    m[i, 0] = a[0];
                    m[i, 3] = a[3];
                    a[1] = a[1] - p[i].br_doza + a[0] + a[3];
                    a[0] = 0;
                    a[3] = 0;
                }
                else
                {
                    m[i, 2] = p[i].br_doza - a[1] - a[0] - a[3];
                    m[i, 1] = a[1];
                    m[i, 0] = a[0];
                    m[i, 3] = a[3];
                    a[2] = a[2] - p[i].br_doza + a[1] + a[0] + a[3];
                    a[1] = 0;
                    a[0] = 0;
                    a[3] = 0;
                }
            }
            else
            {
                da = false;
                break;
            }
        }
    }
    if(da == true)
    {
        Console.WriteLine("moguce");
        for (int i = 0; i < N; i++)
        Console.WriteLine(m[i, 0] + " " + m[i, 1] + " " + m[i, 2] + " " + m[i, 3]); 
    }
    else
    Console.WriteLine("nemoguce");
  }
}