open System
let mutable line = Console.ReadLine().Split()
let n = int32(line.[0])
let m_server = int32(line.[1])
let c_server = int32(line.[2])
let mutable a_m = m_server;
let mutable a_c = c_server;
let mutable b_m = m_server;
let mutable b_c = c_server;
let servers = Array.create n 0
let nodes = Array.create n 0
let mutable sz = 0
let mutable cnt_servers = 0;
for i in 0..n - 1 do
let mutable ok = 0
line <- Console.ReadLine().Split()
let z = int32(line.[0])
if z = 0
then
let mutable m = int32(line.[1])
let mutable c = int32(line.[2])
let t = int32(line.[3])
if (t = 1)
then
if a_m - m >= 0 && a_c - c >= 0
then
servers.[sz] <- cnt_servers
nodes.[sz] <- 0
sz <- sz + 1
a_m <- a_m - m
a_c <- a_c - c
ok <- 1
else
if b_m - m >= 0 && b_c - c >= 0
then
servers.[sz] <- cnt_servers
nodes.[sz] <- 1
sz <- sz + 1
b_m <- b_m - m
b_c <- b_c - c
ok <- 1
else
if a_m - m/2 >= 0 && a_c - c/2 >= 0 && b_m - m/2 >= 0 && b_c - c/2 >= 0
then
servers.[sz] <- cnt_servers
nodes.[sz] <- -1
sz <- sz + 1
a_m <- a_m - m/2
a_c <- a_c - c/2
b_m <- b_m - m/2
b_c <- b_c - c/2
ok <- 1
if ok = 0
then
cnt_servers <- cnt_servers + 1;
a_m <- m_server
a_c <- c_server
b_m <- m_server
b_c <- c_server
servers.[sz] <- cnt_servers
nodes.[sz] <- 0
sz <- sz + 1
m <- m / t
c <- c / t
a_m <- a_m - m
a_c <- a_c - c
if t = 2
then
b_m <- b_m - m
b_c <- b_c - c
nodes.[sz - 1] <- -1
printfn "%d" (int32(cnt_servers + 1))
for i in 0..sz-1 do
if nodes.[i] = 0
then
printfn "%d A" (int32(servers.[i] + 1))
if nodes.[i] = 1
then
printfn "%d B" (int32(servers.[i] + 1))
if nodes.[i] = -1
then
printfn "%d" (int32(servers.[i] + 1))