#include "bits/stdc++.h"
using namespace std;
int main(int argc, char* argv[])
{
int n, m_server, c_server;
cin>>n>>m_server>>c_server;
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;
vector<int> servers;
vector<int> nodes;
int cnt_servers = 0;
for (int i = 0; i < n; i++)
{
int z;
cin>>z;
if (z == 0)
{
int m, c, t;
cin>>m>>c>>t;
if (t == 1)
{
if (a_m - m >= 0 && a_c - c >= 0)
{
servers.push_back(cnt_servers);
nodes.push_back(0);
a_m -= m;
a_c -= c;
continue;
}
if (b_m - m >= 0 && b_c - c >= 0)
{
servers.push_back(cnt_servers);
nodes.push_back(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.push_back(cnt_servers);
nodes.push_back(-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.push_back(cnt_servers);
nodes.push_back(0);
m /= t;
c /= t;
a_m -= m;
a_c -= c;
if (t == 2)
{
b_m -= m;
b_c -= c;
nodes.back() = -1;
}
}
else
{
int id;
cin>>id;
}
}
cout<<cnt_servers + 1<<endl;
for (int i = 0; i < servers.size(); i++)
{
cout<<servers[i] + 1;
if (nodes[i] != -1) cout<<" "<<(char)('A' + nodes[i]);
cout<<endl;
}
}