#include <bits/stdc++.h>
using namespace std;
const int NUM_NODES = 10;
const int NUM_TYPES = 3;
const int MAX_BATCH_SIZE = 16;
const int MAX_NUM_PACKETS = 100000;
struct Packet
{
int type;
int arriveTime;
int t;
};
Packet packets[MAX_NUM_PACKETS];
int cost[NUM_NODES + 1][NUM_TYPES + 1][MAX_BATCH_SIZE + 1];
int batchLimit[NUM_NODES + 1][NUM_TYPES + 1];
vector<int> ids[NUM_NODES + 1];
int c4, c6, cr;
int n, curTime = 1, nout = 0, queueTime = 0;
map<pair<int, int>, int> nextNode =
{
{{1, 1}, 2},
{{2, 1}, 3},
{{3, 1}, 4},
{{4, 1}, 5},
{{5, 1}, 6},
{{6, 1}, 7},
{{7, 1}, 8},
{{8, 1}, 9},
{{9, 1}, 10},
{{1, 2}, 2},
{{2, 2}, 3},
{{3, 2}, 8},
{{8, 2}, 9},
{{9, 2}, 10},
{{1, 3}, 2},
{{2, 3}, 9},
{{9, 3}, 10}
};
void ReceivePackets(int t)
{
curTime = t + cr;
cout << 'R' << " " << t << "\n";
cout.flush();
int p, id, type, a;
cin >> p;
if (p == -1)
{
exit(0);
}
for (int i = 0; i < p; ++i)
{
cin >> id >> type >> a;
packets[id].type = type;
packets[id].arriveTime = a;
packets[id].t = curTime;
ids[1].push_back(id);
}
}
void ExecuteTask(int nodeId, vector<int> arr, int t)
{
int b = arr.size(), type = packets[arr[0]].type;
cout << 'E' << " " << t << " " << nodeId << " " << b;
for (int i = 0; i < b; ++i)
{
cout << " " << arr[i];
}
cout << "\n";
cout.flush();
int p;
cin >> p;
if (p == -1)
{
exit(0);
}
int curCost = cost[nodeId][type][b];
curTime = t + curCost;
for (int i = 0; i < b; ++i)
{
packets[arr[i]].t = curTime;
}
if (nextNode.count({nodeId, type}))
{
int nextNodeId = nextNode[{nodeId, type}];
for (int i = 0; i < b; ++i)
{
ids[nextNodeId].push_back(arr[i]);
}
}
if (nodeId == NUM_NODES)
{
nout += b;
if (nout == n)
{
exit(0);
}
}
// hardware accelerator
if (nodeId == 4 || nodeId == 6)
{
for (int i = 0; i < b; ++i)
{
packets[arr[i]].t = max(curTime, queueTime) + (nodeId == 4 ? c4 : c6);
queueTime = packets[arr[i]].t;
}
}
}
void TakeSinglePacket(int i)
{
vector<int> arr;
arr.push_back(ids[i][0]);
ids[i].erase(ids[i].begin());
ExecuteTask(i, arr, curTime);
}
int main()
{
ios::sync_with_stdio(false); // cin.tie(0);
for (int i1 = 0; i1 < 20; ++i1)
{
int i, j, b;
cin >> i >> j >> b;
batchLimit[i][j] = b;
for (int k = 1; k <= b; ++k)
{
cin >> cost[i][j][k];
}
}
cin >> c4 >> c6 >> cr;
cin >> n;
while (true)
{
bool any = false;
for (int i = 1; i <= NUM_NODES; ++i)
{
if (ids[i].size() && packets[ids[i][0]].t <= curTime)
{
any = true;
TakeSinglePacket(i);
}
}
if (any)
{
continue;
}
ReceivePackets(curTime);
}
return 0;
}