#include<bits/stdc++.h>
using namespace std;
int N;
int X=1025, Y=1025;
int btree[1030][1030], matrix[1030][1030];
int mod (int a, int b) {
int ans = a%b;
if(ans < 0)
ans+=b;
return ans;
}
void update(int x, int y, int val) {
while(x<=X) {
int yy= y;
while(yy <= Y) {
btree[x][yy]+=val;
yy+= yy & -yy;
}
x+= x & -x;
}
}
int query(int x, int y) {
int res=0;
while(x>0) {
int yy =y;
while(yy>0) {
res+=btree[x][yy];
yy-=yy& -yy;
}
x-=x& -x;
}
return res;
}
map<char,int> mp;
int main() {
int n, m;
cin >> n >> m;
string s;
mp['N']=0;
mp['E']=1;
mp['W']=2;
mp['S'] = 3;
char x;
map<int, char> mp1;
mp1[0]='N';
mp1[1]='E';
mp1[2]='W';
mp1[3]='S';
memset(btree,0,sizeof(btree));
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
scanf("\n%c",&x);
update(i,j,mp[x]);
update(i+1,j,-mp[x]);
update(i,j+1,-mp[x]);
update(i+1,j+1,mp[x]);
}
}
int q;
scanf("%d",&q);
for(int i=0;i<q;i++) {
char cmd;
scanf("\n%c",&cmd);
if(cmd=='C') {
int x1,x2,y1,y2,d;
scanf("%d %d %d %d %d",&x1,&y1,&x2,&y2,&d);
int val;
if(d==0) {
val=1;
}
else
val=-1;
update(x1,y1,val);
update(x2+1,y1,-val);
update(x1,y2+1,-val);
update(x2+1,y2+1,val);
}
else
{
int x,y;
scanf("%d %d",&x,&y);
int res= query(x,y);
printf("%c\n",mp1[mod(res,4)]);
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IE47CmludCBYPTEwMjUsIFk9MTAyNTsKaW50IGJ0cmVlWzEwMzBdWzEwMzBdLCBtYXRyaXhbMTAzMF1bMTAzMF07CmludCAgbW9kIChpbnQgYSwgaW50IGIpIHsKCWludCBhbnMgPSBhJWI7CglpZihhbnMgPCAwKSAKCQlhbnMrPWI7CglyZX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