#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<time.h>
#define ll long long
#define oo 1000000009
#define MAXN 1005
#define pi acos(-1.0)
#define esp 1e-30
#define MAXD 4
using namespace std;
int sum[MAXN][MAXN],N;
void updateX(int x,int y,int d)
{
while (x<=N)
{
sum[y][x]+=d;
x+=x&(-x);
}
}
void update(int x,int y,int d)
{
if (!y || !x) return;
while (y<=N)
{
updateX(x,y,d);
y+=y&(-y);
}
}
int queryX(int x,int y)
{
int ans=0;
while (x)
{
ans+=sum[y][x];
x-=x&(-x);
}
return ans;
}
int query(int x,int y)
{
if (!y || !x) return 0;
int ans=0;
while (y)
{
ans+=queryX(x,y);
y-=y&(-y);
}
return ans;
}
int main()
{
int T,Q,cases,x1,y1,x2,y2,x,y;
char c;
scanf("%d",&T);
for (cases=1;cases<=T;cases++)
{
scanf("%d%d",&N,&Q);
memset(sum,0,sizeof(sum));
while (Q--)
{
do { c=getchar(); } while (c!='C' && c!='Q');
if (c=='C')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2),x2++,y2++;
update(x1,y1,1),update(x2,y2,1);
update(x1,y2,-1),update(x2,y1,-1);
}else
{
scanf("%d%d",&x,&y);
x1=query(x,y);
printf("%d\n",x1&1);
}
}
if (cases!=T) printf("\n");
}
return 0;
}