1 #include<cstdio> 2 #include<cstring> 3 #define MAXN 1010 4 int ans,n,tree[MAXN<<2][MAXN<<2]; 5 void SubBuild(int t,int L,int R,int rt) 6 { 7 tree[t][rt]=0; 8 if(L!=R) 9 { 10 int mid=(L+R)>>1; 11 SubBuild(t,L,mid,rt<<1); 12 SubBuild(t,mid+1,R,rt<<1|1); 13 } 14 } 15 void Build(int L,int R,int rt) 16 { 17 SubBuild(rt,1,n,1); 18 if(L!=R) 19 { 20 int mid=(L+R)>>1; 21 Build(L,mid,rt<<1); 22 Build(mid+1,R,rt<<1|1); 23 } 24 } 25 void SubUpdate(int t,int y1,int y2,int L,int R,int rt) 26 { 27 if(y1<=L&&R<=y2) 28 tree[t][rt]^=1; 29 else 30 { 31 int mid=(L+R)>>1; 32 if(y1<=mid) 33 SubUpdate(t,y1,y2,L,mid,rt<<1); 34 if(y2>mid) 35 SubUpdate(t,y1,y2,mid+1,R,rt<<1|1); 36 } 37 } 38 void Update(int x1,int x2,int y1,int y2,int L,int R,int rt) 39 { 40 if(x1<=L&&R<=x2) 41 SubUpdate(rt,y1,y2,1,n,1); 42 else 43 { 44 int mid=(L+R)>>1; 45 if(x1<=mid) 46 Update(x1,x2,y1,y2,L,mid,rt<<1); 47 if(x2>mid) 48 Update(x1,x2,y1,y2,mid+1,R,rt<<1|1); 49 } 50 } 51 void SubQuery(int t,int x,int L,int R,int rt) 52 { 53 ans^=tree[t][rt]; 54 if(L!=R) 55 { 56 int mid=(L+R)>>1; 57 if(x<=mid) 58 SubQuery(t,x,L,mid,rt<<1); 59 else 60 SubQuery(t,x,mid+1,R,rt<<1|1); 61 } 62 } 63 void Query(int x,int y,int L,int R,int rt) 64 { 65 SubQuery(rt,y,1,n,1); 66 if(L!=R) 67 { 68 int mid=(L+R)>>1; 69 if(x<=mid) 70 Query(x,y,L,mid,rt<<1); 71 else 72 Query(x,y,mid+1,R,rt<<1|1); 73 } 74 } 75 int main() 76 { 77 char ch; 78 int t,q,x1,y1,x2,y2; 79 scanf("%d",&t); 80 while(t--) 81 { 82 scanf("%d%d",&n,&q); 83 Build(1,n,1); 84 while(q--) 85 { 86 scanf(" %c%d%d",&ch,&x1,&y1); 87 if(ch=='C') 88 { 89 scanf("%d%d",&x2,&y2); 90 Update(x1,x2,y1,y2,1,n,1); 91 } 92 else 93 { 94 ans=0; 95 Query(x1,y1,1,n,1); 96 printf("%d\n",ans); 97 } 98 } 99 if(t) 100 putchar('\n'); 101 } 102 return 0; 103 }