#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int gra[105][105];
struct node
{
int xx,yy,sta;
}ro[105];
int k,a,b,n,m;
bool check( int x, int y)
{
if(x > 0 && x <= a && y > 0 && y<=b)
return true;
return false;
}
int main()
{
bool flag ;
scanf("%d",&k);
while(k--)
{
int x,y;
char s;
flag = false;
scanf("%d %d",&a, &b);
//cout<<"a"<<a<<" "<<"b"<<b<<endl;
for( int i = 1; i<=a; i++)
for( int j = 1; j<=b; j++)
gra[i][j] = -1;
scanf("%d %d",&n, &m);
for( int i = 1; i<=n; i++)
{
cin>>x>>y>>s;
gra[x][y] = i;
ro[i].xx = x;
ro[i].yy = y;
//cout<<"i"<<i<< "y"<<y<<endl;
switch(s)
{
case 'N':
{
ro[i].sta = 0;
break;
}
case 'W':
{
ro[i].sta = 1;
break;
}
case 'S' :
{
ro[i].sta = 2;
break;
}
case 'E' :
{
ro[i].sta = 3;
break;
}
}
//cout<<"input cover"<<endl;
}
for( int i = 0; i<m; i++)
{
int num;
int p;
cin>>num>>s>>p;
// cout<<ro[num].sta<<endl;
if(flag)
continue;
switch (s)
{
case 'L':
{ int rep;
rep = p%4;
ro[num].sta = (ro[num].sta+rep+4)%4;
//cout<<ro[num].sta<<endl;
break;
}
case 'R':
{
int rep;
rep = p%4;
ro[num].sta = (ro[num].sta-rep+4)%4;
//cout<<ro[num].sta<<endl;
break;
}
case 'F':
{
if(ro[num].sta == 0)
{
while(p--)
{
// cout<<p<<" cxvdf"<<endl;
if(check(ro[num].xx,ro[num].yy+1))
{
gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx][ro[num].yy+1]==-1)
{
ro[num].yy++;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx][ro[num].yy+1]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 1)
{
while(p--)
{
if(check(ro[num].xx-1,ro[num].yy))
{
gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx-1][ro[num].yy]==-1)
{
ro[num].xx--;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx-1][ro[num].yy]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 2)
{
while(p--)
{
if(check(ro[num].xx,ro[num].yy-1))
{ gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx][ro[num].yy-1]==-1)
{
ro[num].yy--;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx][ro[num].yy-1]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 3)
{
while(p--)
{
//cout<<"p "<<p<<endl;
if(check(ro[num].xx+1,ro[num].yy))
{ gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx+1][ro[num].yy]==-1)
{
ro[num].xx++;
// cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx+1][ro[num].yy]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
break;
}
}
}
if(!flag)
cout<<"OK"<<endl;
}
}
#include <stdio.h>
#include <string.h>
using namespace std;
int gra[105][105];
struct node
{
int xx,yy,sta;
}ro[105];
int k,a,b,n,m;
bool check( int x, int y)
{
if(x > 0 && x <= a && y > 0 && y<=b)
return true;
return false;
}
int main()
{
bool flag ;
scanf("%d",&k);
while(k--)
{
int x,y;
char s;
flag = false;
scanf("%d %d",&a, &b);
//cout<<"a"<<a<<" "<<"b"<<b<<endl;
for( int i = 1; i<=a; i++)
for( int j = 1; j<=b; j++)
gra[i][j] = -1;
scanf("%d %d",&n, &m);
for( int i = 1; i<=n; i++)
{
cin>>x>>y>>s;
gra[x][y] = i;
ro[i].xx = x;
ro[i].yy = y;
//cout<<"i"<<i<< "y"<<y<<endl;
switch(s)
{
case 'N':
{
ro[i].sta = 0;
break;
}
case 'W':
{
ro[i].sta = 1;
break;
}
case 'S' :
{
ro[i].sta = 2;
break;
}
case 'E' :
{
ro[i].sta = 3;
break;
}
}
//cout<<"input cover"<<endl;
}
for( int i = 0; i<m; i++)
{
int num;
int p;
cin>>num>>s>>p;
// cout<<ro[num].sta<<endl;
if(flag)
continue;
switch (s)
{
case 'L':
{ int rep;
rep = p%4;
ro[num].sta = (ro[num].sta+rep+4)%4;
//cout<<ro[num].sta<<endl;
break;
}
case 'R':
{
int rep;
rep = p%4;
ro[num].sta = (ro[num].sta-rep+4)%4;
//cout<<ro[num].sta<<endl;
break;
}
case 'F':
{
if(ro[num].sta == 0)
{
while(p--)
{
// cout<<p<<" cxvdf"<<endl;
if(check(ro[num].xx,ro[num].yy+1))
{
gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx][ro[num].yy+1]==-1)
{
ro[num].yy++;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx][ro[num].yy+1]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 1)
{
while(p--)
{
if(check(ro[num].xx-1,ro[num].yy))
{
gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx-1][ro[num].yy]==-1)
{
ro[num].xx--;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx-1][ro[num].yy]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 2)
{
while(p--)
{
if(check(ro[num].xx,ro[num].yy-1))
{ gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx][ro[num].yy-1]==-1)
{
ro[num].yy--;
//cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx][ro[num].yy-1]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
else if(ro[num].sta == 3)
{
while(p--)
{
//cout<<"p "<<p<<endl;
if(check(ro[num].xx+1,ro[num].yy))
{ gra[ro[num].xx][ro[num].yy] = -1;
if(gra[ro[num].xx+1][ro[num].yy]==-1)
{
ro[num].xx++;
// cout<<ro[num].xx<<" "<<ro[num].yy<<endl;
}
else
{
cout<<"Robot "<<num<<" crashes into robot "<<gra[ro[num].xx+1][ro[num].yy]<<endl;
flag = true;
break;
}
gra[ro[num].xx][ro[num].yy] = num;
}
else
{
cout<<"Robot "<<num<<" crashes into the wall"<<endl;
flag = true;
break;
}
}
}
break;
}
}
}
if(!flag)
cout<<"OK"<<endl;
}
}