#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>
#include <vector>
using namespace std;
const int MAXSIZE = 25;
int testcase;
int A, B;
int N, M;
int direction[4] = {0, 1, 2, 3};
class MInstruction{
public:
int robotId;
char action;
int repeat;
MInstruction(int robotid, char action, int repeat){
this->robotId = robotid;
this->action = action;
this->repeat = repeat;
}
};
class Robot{
public:
int robotID;
pair<int, int> pairs;
int direction;
Robot(int robotID, pair<int ,int >pairs, char direction):
robotID(robotID), pairs(pairs),direction(direction){}
};
bool isin(pair<int, int > pair1){
int h = pair1.first;
int v = pair1.second;
return h>=1&&h<=A&&v>=1&&v<=B;
}
vector<MInstruction> insvec;
vector<Robot> robotvec;
bool exeins(Robot & robot, MInstruction & instuction){
char d = instuction.action;
if (d == 'F'){
for (int j = 0; j < instuction.repeat; ++j) {
if (robot.direction == 0) robot.pairs.second++;
else if (robot.direction == 1) robot.pairs.first--;
else if (robot.direction == 2) robot.pairs.second--;
else if (robot.direction == 3) robot.pairs.first++;
for (int i = 0; i <N; ++i) {
if (!isin(robot.pairs)){
cout<<"Robot "<<robot.robotID<<" crashes into the wall"<<endl;
return false;
}
if (robotvec[i].robotID == robot.robotID) continue;
if (robot.pairs.first == robotvec[i].pairs.first&&
robot.pairs.second == robotvec[i].pairs.second){
cout<<"Robot "<<robot.robotID<<" crashes into robot "<<robotvec[i].robotID<<endl;
return false;
}
}
}
} else if (d == 'L'){
int r = instuction.repeat;
robot.direction = (robot.direction+r)%4;
} else if (d == 'R'){
int r = instuction.repeat%4;
robot.direction = (robot.direction-r+4)%4;
}
return true;
}
int getdir(char d){
switch (d){
case 'N':
return 0;
case 'W':
return 1;
case 'S':
return 2;
case 'E':
return 3;
default:
return -1;
}
}
int main(){
cin>>testcase;
while (testcase--){
insvec.clear();
robotvec.clear();
cin>>A>>B>>N>>M;
for (int i = 1; i <= N ; ++i) {
int x, y;
char dir;
cin>>x>>y>>dir;
int temp = getdir(dir);
robotvec.push_back(Robot(i, make_pair(x, y),temp));
}
for (int i = 0; i < M; ++i) {
int robotid;
char dir;
int times;
cin>>robotid>>dir>>times;
insvec.push_back(MInstruction(robotid, dir, times));
}
for (int i = 0; i < M; ++i) {
MInstruction ins = insvec[i];
for (int j = 0; j <N ; ++j) {
if (ins.robotId == robotvec[j].robotID){
if (exeins(robotvec[j], ins)){
break;
} else{
goto die;
}
}
}
}
cout<<"OK"<<endl;
continue;
die:
continue;
}
}