#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define lowbit(x) (x&(-x))
bool c[1010][1010];
int n;
 bool sum(int x,int y) {
bool s=0;
 while(x) {
int yy=y;
 while(yy) {
s^=c[x][yy];
yy-=lowbit(yy);
}
x-=lowbit(x);
}
return s;
}
 void update(int x,int y) {
 while(x<=n) {
int yy=y;
 while(yy<=n) {
c[x][yy]=!c[x][yy];
yy+=lowbit(yy);
}
x+=lowbit(x);
}
}
 int main() {
int t,x,y,xx,yy,m;
char s[2];
scanf("%d",&t);
 while(t--) {
memset(c,0,sizeof(c));
scanf("%d%d",&n,&m);
 while(m--) {
scanf("%s",s);
 if(s[0]=='C') {
scanf("%d%d%d%d",&x,&y,&xx,&yy);
update(++xx,++yy);
update(x,yy);
update(xx,y);
update(x,y);
 }else {
scanf("%d%d",&x,&y);
printf("%d\n",sum(x,y));
}
}
puts("");
}
return 0;
}

|