#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#define mp make_pair
#define pa pair<int,int>
#define pb push_back
#define fi first
#define se second
using namespace std;
inline void Get_Int(int &X)
{
X=0; char ch=getchar(); int f=1;
while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0' && ch<='9') {X=X*10+ch-'0'; ch=getchar();} X*=f;
}
inline void Put_Int(int X)
{
char ch[20]; int top=0;
if (X==0) ch[++top]='0';
while (X) ch[++top]=X%10+'0',X/=10;
while (top) putchar(ch[top--]); putchar('
');
}
//=======================================
const int Maxn=4010;
int x1,x2,y1,y2,Ans;
bool Key[Maxn][Maxn];
int n,Q,Kase;
void Modify_Y(int ox,int oy,int l,int r,int p,int q)
{
if (l==p && r==q)
{
Key[ox][oy]^=1;
return;
}
int mid=(l+r)>>1;
if (q<=mid) Modify_Y(ox,oy<<1,l,mid,p,q);
if (p>=mid+1) Modify_Y(ox,oy<<1|1,mid+1,r,p,q);
if (p<=mid && q>=mid+1) Modify_Y(ox,oy<<1,l,mid,p,mid),Modify_Y(ox,oy<<1|1,mid+1,r,mid+1,q);
}
void Modify_X(int ox,int l,int r,int p,int q)
{
if (l==p && r==q)
{
Modify_Y(ox,1,1,n,y1,y2);
return;
}
int mid=(l+r)>>1;
if (q<=mid) Modify_X(ox<<1,l,mid,p,q);
if (p>=mid+1) Modify_X(ox<<1|1,mid+1,r,p,q);
if (p<=mid && q>=mid+1) Modify_X(ox<<1,l,mid,p,mid),Modify_X(ox<<1|1,mid+1,r,mid+1,q);
}
void Query_Y(int ox,int oy,int l,int r)
{
Ans^=Key[ox][oy];
if (l==r) return;
int mid=(l+r)>>1;
if (y1<=mid) Query_Y(ox,oy<<1,l,mid);
if (y1>=mid+1) Query_Y(ox,oy<<1|1,mid+1,r);
}
void Query_X(int ox,int l,int r)
{
Query_Y(ox,1,1,n);
if (l==r) return;
int mid=(l+r)>>1;
if (x1<=mid) Query_X(ox<<1,l,mid);
if (x1>=mid+1) Query_X(ox<<1|1,mid+1,r);
}
int main()
{
Get_Int(Kase);
for (int kase=1;kase<=Kase;kase++)
{
Get_Int(n),Get_Int(Q);
memset(Key,false,sizeof(Key));
for (int i=1;i<=Q;i++)
{
char ch=getchar(); while (ch!='C' && ch!='Q') ch=getchar();
if (ch=='C')
{
Get_Int(x1),Get_Int(y1),Get_Int(x2),Get_Int(y2);
Modify_X(1,1,n,x1,x2);
}
if (ch=='Q')
{
Get_Int(x1),Get_Int(y1);
Ans=0;
Query_X(1,1,n);
Put_Int(Ans);
}
}
putchar('
');
}
return 0;
}