n, m_server, c_server = [int(x) for x in input().strip().split(' ')]
a_m = m_server
a_c = c_server
b_m = m_server
b_c = c_server
servers = []
nodes = []
cnt_servers = 0
for _ in range(n):
inp = [int(x) for x in input().strip().split(' ')]
if inp[0] == 0:
m = inp[1]
c = inp[2]
t = inp[3]
if t == 1:
if a_m - m >= 0 and a_c - c >= 0:
servers += [cnt_servers]
nodes += [0]
a_m -= m
a_c -= c
continue
if b_m - m >= 0 and b_c - c >= 0:
servers += [cnt_servers]
nodes += [1]
b_m -= m
b_c -= c
continue
else:
if a_m - m/2 >= 0 and a_c - c/2 >= 0 and b_m - m/2 >= 0 and b_c - c/2 >= 0:
servers += [cnt_servers]
nodes += [-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 += [cnt_servers]
nodes += [0]
m //= t
c //= t
a_m -= m
a_c -= c
if t == 2:
b_m -= m
b_c -= c
nodes[-1] = -1
print(cnt_servers + 1)
for s, n in zip(servers, nodes):
if n == 0:
print(s + 1, 'A')
if n == 1:
print(s + 1, 'B')
if n == -1:
print(s + 1)