#include <bits/stdc++.h>
using namespace std;
const int MAX_ROBOT = 100 + 5;
const int MAX_COMMAND = 10 + 5;
int n, m, K;
struct Command{
string CommandName;
int h, x, y;
string TriggerCheck;
Command* SubCommand;
};
struct Robot{
int l, r;
Command command[MAX_COMMAND];
}bot[MAX_ROBOT];
void read(Command &obj);
void Slackoff(int i, int j);
void Move(int i, int j);
void Swap(int i, int j);
void Mirror(int i, int j);
void Replace(int i, int j);
void Activate(int i, int j);
void Trigger(int i, int j);
void Do(int i, int j);
void Running(int i, int j);
void read(Command &obj){
cin >> obj.CommandName;
if(obj.CommandName == "MOVE"){
cin >> obj.h >> obj.x;
}else if(obj.CommandName == "SWAP"){
cin >> obj.h >> obj.x >> obj.y;
obj.x --, obj.y --;
}else if(obj.CommandName == "MIRROR"){
cin >> obj.h >> obj.x;
obj.x --;
}else if(obj.CommandName == "REPLACE"){
cin >> obj.h >> obj.x;
obj.x --;
obj.SubCommand = new Command;
read(*(obj.SubCommand));
}else if(obj.CommandName == "ACTIVATE"){
cin >> obj.h;
}else if(obj.CommandName == "TRIGGER"){
cin >> obj.TriggerCheck;
obj.TriggerCheck.pop_back();
obj.SubCommand = new Command;
read(*(obj.SubCommand));
}
}
void Slackoff(int i, int j){
K --;
cout << "Robot " << i << " slacks off." << endl;
}
void Move(int i, int j){
K --;
cout << "Robot " << i << " moves its ";
if(bot[i].command[j].h == 0){
bot[i].l = (bot[i].l + bot[i].command[j].x) % n;
cout << "left hand towards Robot " << bot[i].l << "." << endl;
}else{
bot[i].r = (bot[i].r + bot[i].command[j].x) % n;
cout << "right hand towards Robot " << bot[i].r << "." << endl;
}
}
void Swap(int i, int j){
K --;
if(bot[i].command[j].h == 0){
swap(bot[bot[i].l].command[bot[i].command[j].x], bot[i].command[bot[i].command[j].y]);
cout << "Robot " << i << " swaps a line of command with Robot " << bot[i].l << "." << endl;
}else{
swap(bot[bot[i].r].command[bot[i].command[j].x], bot[i].command[bot[i].command[j].y]);
cout << "Robot " << i << " swaps a line of command with Robot " << bot[i].r << "." << endl;
}
}
void Mirror(int i, int j){
K --;
if(bot[i].command[j].h == 0){
if(bot[i].command[j].CommandName != "TRIGGER")
bot[bot[i].l].command[bot[i].command[j].x].h ^= 1;
else
bot[bot[i].l].command[bot[i].command[j].x].SubCommand -> h ^= 1;
cout << "Robot " << i << " modifies a line of command of Robot " << bot[i].l << "." << endl;
}else{
if(bot[i].command[j].CommandName != "TRIGGER")
bot[bot[i].r].command[bot[i].command[j].x].h ^= 1;
else
bot[bot[i].r].command[bot[i].command[j].x].SubCommand -> h ^= 1;
cout << "Robot " << i << " modifies a line of command of Robot " << bot[i].r << "." << endl;
}
}
void Replace(int i, int j){
K --;
if(bot[i].command[j].h == 0){
bot[bot[i].l].command[bot[i].command[j].x] = *(bot[i].command[j].SubCommand);
cout << "Robot " << i << " replaces a line of command of Robot " << bot[i].l << "." << endl;
}else{
bot[bot[i].r].command[bot[i].command[j].x] = *(bot[i].command[j].SubCommand);
cout << "Robot " << i << " replaces a line of command of Robot " << bot[i].r << "." << endl;
}
}
void Activate(int i, int j){
K --;
if(bot[i].command[j].h == 0){
cout << "Robot " << i << " activates Robot " << bot[i].l << "." << endl;
for(int p = 0; p < m; p ++){
Running(bot[i].l, p);
}
}else{
cout << "Robot " << i << " activates Robot " << bot[i].r << "." << endl;
for(int p = 0; p < m; p ++){
Running(bot[i].r, p);
}
}
}
void Trigger(int i, int j){
Command temp = bot[i].command[j];
bot[i].command[j] = *(bot[i].command[j].SubCommand);
Running(i, j);
bot[i].command[j] = temp;
}
void Do(int i, int j){
if(bot[i].r != i){
Command lastCommand = bot[i].command[j];
bool isTrigger = (lastCommand.CommandName == "TRIGGER");
for(int k = 0; k < m; k++){
if(bot[bot[i].r].command[k].CommandName == "TRIGGER"){
if(bot[bot[i].r].command[k].TriggerCheck != "TRIGGER"){
if(!isTrigger && bot[bot[i].r].command[k].TriggerCheck == lastCommand.CommandName){
Running(bot[i].r, k);
break;
}else if(isTrigger && bot[bot[i].r].command[k].TriggerCheck == lastCommand.SubCommand->CommandName){
Running(bot[i].r, k);
break;
}
}else{
if(isTrigger){
Running(bot[i].r, k);
break;
}
}
}
}
}
}
void Running(int i, int j){
if(K <= 0) exit(0);
if(bot[i].command[j].CommandName == "SLACKOFF") Slackoff(i, j);
else if(bot[i].command[j].CommandName == "MOVE") Move(i, j);
else if(bot[i].command[j].CommandName == "SWAP") Swap(i, j);
else if(bot[i].command[j].CommandName == "MIRROR") Mirror(i, j);
else if(bot[i].command[j].CommandName == "REPLACE") Replace(i, j);
else if(bot[i].command[j].CommandName == "ACTIVATE") Activate(i, j);
else Trigger(i, j);
Do(i, j);
}
int main(){
cin >> n >> m >> K;
for(int i = 0; i < n; i ++){
cin >> bot[i].l >> bot[i].r;
for(int j = 0; j < m; j ++)
read(bot[i].command[j]);
}
for(int i = 0; i < n; i ++){
for(int j = 0; j < m; j ++){
if(bot[i].command[j].CommandName != "TRIGGER"){
Running(i, j);
}
}
}
}