using System;
using System.Collections.Generic;
class main
{
public static void Main(string[] args)
{
int n, m_server, c_server;
string[] line = Console.ReadLine().Split(' ');
n = Int32.Parse(line[0]);
m_server = Int32.Parse(line[1]);
c_server = Int32.Parse(line[2]);
int a_m, a_c, b_m, b_c;
a_m = m_server;
a_c = c_server;
b_m = m_server;
b_c = c_server;
List<int> servers = new List<int>();
List<int> nodes = new List<int>();
int cnt_servers = 0;
for (int i = 0; i < n; i++)
{
line = Console.ReadLine().Split(' ');
int z = Int32.Parse(line[0]);
if (z == 0)
{
int m, c, t;
m = Int32.Parse(line[1]);
c = Int32.Parse(line[2]);
t = Int32.Parse(line[3]);
if (t == 1)
{
if (a_m - m >= 0 && a_c - c >= 0)
{
servers.Add(cnt_servers);
nodes.Add(0);
a_m -= m;
a_c -= c;
continue;
}
if (b_m - m >= 0 && b_c - c >= 0)
{
servers.Add(cnt_servers);
nodes.Add(1);
b_m -= m;
b_c -= c;
continue;
}
}
else
{
if (a_m - m/2 >= 0 && a_c - c/2 >= 0 && b_m - m/2 >= 0 && b_c - c/2 >= 0)
{
servers.Add(cnt_servers);
nodes.Add(-1);
a_m -= m/2;
a_c -= c/2;
b_m -= m/2;
b_c -= c/2;
continue;
}
}
cnt_servers += 1;
a_m = m_server;
a_c = c_server;
b_m = m_server;
b_c = c_server;
servers.Add(cnt_servers);
nodes.Add(0);
m /= t;
c /= t;
a_m -= m;
a_c -= c;
if (t == 2)
{
b_m -= m;
b_c -= c;
nodes[nodes.Count - 1] = -1;
}
}
}
Console.WriteLine(cnt_servers + 1);
for (int i = 0; i < servers.Count; i++)
{
if (nodes[i] == 0)
Console.WriteLine((servers[i] + 1).ToString() + " A");
if (nodes[i] == 1)
Console.WriteLine((servers[i] + 1).ToString() + " B");
if (nodes[i] == -1)
Console.WriteLine(servers[i] + 1);
}
}
}