#include <bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
int n,m,k;
struct Order{
string name;
int h,x,y,z;
string cmdname;
int id;
Order(){name=cmdname="";h=x=y=z=id=0;}
};
vector<Order> ulst;
struct Robot{
int l_hand,r_hand;
vector<Order> lst;
}bot[105];
void Input();
Order Analyze();
void Work(int now);
void Trigger(int now,string t,int ist);
void Do(int now,Order x,int ist);
int main(){
freopen("5.in","r",stdin);
freopen("5.out","w",stdout);
Input(); int now=0;
while(k>0)
Work(now),now=(now+1)%n;
return 0;
}
void Input(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m>>k;
F(i,0,n-1){
cin>>bot[i].l_hand>>bot[i].r_hand;
F(j,1,m){
Order res=Analyze();
bot[i].lst.push_back(res);
}
}
}
Order Analyze(){
Order res; string s,cmd,cname; cin>>s;
int H,X,Y,Z; res.name=s;
if(s=="MOVE") cin>>H>>Z,res.h=H,res.z=Z;
if(s=="SWAP") cin>>H>>X>>Y,res.h=H,res.x=X,res.y=Y;
if(s=="MIRROR") cin>>H>>X,res.h=H,res.x=X;
if(s=="ACTIVATE") cin>>H,res.h=H;
if(s=="REPLACE") {
cin>>H>>X,res.h=H,res.x=X;
Order cmd=Analyze(); ulst.push_back(cmd);
res.id=int(ulst.size())-1;
}
if(s=="TRIGGER"){
cin>>cname; cname.pop_back(); res.cmdname=cname;
Order cmd=Analyze();ulst.push_back(cmd);
res.id=int(ulst.size())-1;
}
return res;
}
void Work(int now){
for(auto x:bot[now].lst){
Do(now,x,0);
}
}
void Do(int now,Order x,int ist){
if(k<=0) exit(0);
string t=x.name;
if(t=="SLACKOFF"){
cout<<"Robot "<<now<<" slacks off.\n";k--;
} if(t=="MOVE"){
int to;
if(x.h==0) to=(bot[now].l_hand+=x.z)%=n;
else to=(bot[now].r_hand+=x.z)%=n;
cout<<"Robot "<<now<<" moves its "<<(x.h==0?"left":"right")<<" hand towards Robot "<<to<<".\n";k--;
} if(t=="SWAP"){
int to=(x.h==0)?bot[now].l_hand:bot[now].r_hand;
cout<<"Robot "<<now<<" swaps a line of command with Robot "<<to<<".\n";k--;
swap(bot[to].lst[x.x-1],bot[now].lst[x.y-1]);
} if(t=="MIRROR"){
int to=(x.h==0)?bot[now].l_hand:bot[now].r_hand;
cout<<"Robot "<<now<<" modifies a line of command of Robot "<<to<<".\n";k--;
if(bot[to].lst[x.x-1].name!="TRIGGER") bot[to].lst[x.x-1].h^=1;
else ulst[bot[to].lst[x.x-1].id].h^=1;
} if(t=="REPLACE"){
int to=(x.h==0)?bot[now].l_hand:bot[now].r_hand;
cout<<"Robot "<<now<<" replaces a line of command of Robot "<<to<<".\n";k--;
bot[to].lst[x.x-1]=ulst[x.id];
} if(t=="ACTIVATE"){
int to=(x.h==0)?bot[now].l_hand:bot[now].r_hand;
cout<<"Robot "<<now<<" activates Robot "<<to<<".\n";k--;
Work(to);
} if(k<=0) exit(0);
if(t!="TRIGGER") Trigger(now,t,ist);
}
void Trigger(int now,string t,int ist){
int to=bot[now].r_hand;
if(to==now) return ;
for(auto x:bot[to].lst){
if(x.name!="TRIGGER") continue;
if(x.cmdname==t||(x.cmdname=="TRIGGER"&&ist==1)){
Do(to,ulst[x.id],1);break;
}
}
}