using System;
using System.Collections.Generic;
class Program
{
const int NUM_NODES = 10;
const int NUM_TYPES = 3;
const int MAX_BATCH_SIZE = 16;
const int MAX_NUM_PACKETS = 100000;
class Packet
{
public int Type;
public int ArriveTime;
public int T;
}
static Packet[] packets = new Packet[MAX_NUM_PACKETS];
static int[,,] cost = new int[NUM_NODES + 1, NUM_TYPES + 1, MAX_BATCH_SIZE + 1];
static int[,] batchLimit = new int[NUM_NODES + 1, NUM_TYPES + 1];
static List<int>[] ids = new List<int>[NUM_NODES + 1];
static int c4, c6, cr;
static int n, curTime = 1, nout = 0, queueTime = 0;
static Dictionary<Tuple<int, int>, int> nextNode = new Dictionary<Tuple<int, int>, int>
{
{ Tuple.Create(1, 1), 2 },
{ Tuple.Create(2, 1), 3 },
{ Tuple.Create(3, 1), 4 },
{ Tuple.Create(4, 1), 5 },
{ Tuple.Create(5, 1), 6 },
{ Tuple.Create(6, 1), 7 },
{ Tuple.Create(7, 1), 8 },
{ Tuple.Create(8, 1), 9 },
{ Tuple.Create(9, 1), 10 },
{ Tuple.Create(1, 2), 2 },
{ Tuple.Create(2, 2), 3 },
{ Tuple.Create(3, 2), 8 },
{ Tuple.Create(8, 2), 9 },
{ Tuple.Create(9, 2), 10 },
{ Tuple.Create(1, 3), 2 },
{ Tuple.Create(2, 3), 9 },
{ Tuple.Create(9, 3), 10 }
};
static void ReceivePackets(int t)
{
curTime = t + cr;
Console.WriteLine($"R {t}");
Console.Out.Flush();
int p = int.Parse(Console.ReadLine());
if (p == -1)
{
Environment.Exit(0);
}
for (int i = 0; i < p; ++i)
{
var inputs = Console.ReadLine().Split();
int id = int.Parse(inputs[0]);
int type = int.Parse(inputs[1]);
int a = int.Parse(inputs[2]);
packets[id] = new Packet();
packets[id].Type = type;
packets[id].ArriveTime = a;
packets[id].T = curTime;
ids[1].Add(id);
}
}
static void ExecuteTask(int nodeId, List<int> arr, int t)
{
int b = arr.Count, type = packets[arr[0]].Type;
Console.Write($"E {t} {nodeId} {b} ");
foreach (var id in arr)
{
Console.Write(id + " ");
}
Console.WriteLine();
Console.Out.Flush();
int p = int.Parse(Console.ReadLine());
if (p == -1)
{
Environment.Exit(0);
}
int curCost = cost[nodeId, type, b];
curTime = t + curCost;
foreach (var id in arr)
{
packets[id].T = curTime;
}
if (nextNode.ContainsKey(Tuple.Create(nodeId, type)))
{
int nextNodeId = nextNode[Tuple.Create(nodeId, type)];
foreach (var id in arr)
{
ids[nextNodeId].Add(id);
}
}
if (nodeId == NUM_NODES)
{
nout += b;
if (nout == n)
{
Environment.Exit(0);
}
}
// hardware accelerator
if (nodeId == 4 || nodeId == 6)
{
foreach (var id in arr)
{
packets[id].T = Math.Max(curTime, queueTime) + (nodeId == 4 ? c4 : c6);
queueTime = packets[id].T;
}
}
}
static void TakeSinglePacket(int i)
{
List<int> arr = new List<int> { ids[i][0] };
ids[i].RemoveAt(0);
ExecuteTask(i, arr, curTime);
}
static void Main()
{
for (int i1 = 0; i1 < 20; ++i1)
{
var inputs = Console.ReadLine().Split();
int i = int.Parse(inputs[0]);
int j = int.Parse(inputs[1]);
int b = int.Parse(inputs[2]);
batchLimit[i, j] = b;
for (int k = 1; k <= b; ++k)
{
cost[i, j, k] = int.Parse(inputs[3 + k - 1]);
}
}
var config = Console.ReadLine().Split();
c4 = int.Parse(config[0]);
c6 = int.Parse(config[1]);
cr = int.Parse(config[2]);
n = int.Parse(Console.ReadLine());
// Initialize lists for ids
for (int i = 0; i <= NUM_NODES; ++i)
{
ids[i] = new List<int>();
}
while (true)
{
bool any = false;
for (int i = 1; i <= NUM_NODES; ++i)
{
if (ids[i].Count > 0 && packets[ids[i][0]].T <= curTime)
{
any = true;
TakeSinglePacket(i);
}
}
if (any)
{
continue;
}
ReceivePackets(curTime);
}
}
}