#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define MX 1001
int x, n, m;
int t = 1;
struct Segy
{
int yl, yr;
bool value, go_down;
};
struct Segx
{
int xl, xr;
bool go_down;
struct Segy segy[3*MX];
}seg[MX*3];
void buildin(int yl, int yr, int p, struct Segy segy[])
{
segy[p].yl = yl;
segy[p].yr = yr;
segy[p].go_down = segy[p].value = false;
if(yl == yr) return ;
int mid = yl+yr>>1, childp = p<<1;
buildin(yl, mid,childp, segy);
buildin(mid+1,yr, childp+1,segy);
}
void buildTree(int xl, int xr, int p)
{
seg[p].xl = xl;
seg[p].xr = xr;
seg[p].go_down = false;
buildin(1,n,1,seg[p].segy);
if(xl == xr) return ;
int mid = xl+xr>>1, childp = p<<1;
buildTree(xl, mid,childp);
buildTree(mid+1,xr, childp+1);
}
void _xory(int yl, int yr, int p, struct Segy segy[])
{
if(yl <= segy[p].yl && yr >= segy[p].yr)
{
segy[p].value ^= true;
return ;
}
if(yl > segy[p].yr || yr < segy[p].yl) return ;
int mid = yl+yr>>1, childp = p<<1;
segy[p].go_down = true;
_xory(yl,yr, childp, segy);
_xory(yl,yr, childp+1, segy);
}
void _xor(int x1, int y1, int x2, int y2, int p)
{
if(x1 <= seg[p].xl && x2 >= seg[p].xr)
{
_xory(y1, y2, 1, seg[p].segy);
return ;
}
if(x1 > seg[p].xr || x2 < seg[p].xl) return ;
seg[p].go_down = true;
int mid = seg[p].xl+seg[p].xr>>1, childp = p<<1;
_xor(x1, y1,x2, y2,childp);
_xor(x1, y1,x2, y2,childp+1);
}
bool query_y(int y, int p, struct Segy segy[])
{
bool result = segy[p].value;
int mid = segy[p].yl+segy[p].yr>>1, childp = p<<1;
if(segy[p].go_down)
{
if(y <= mid) result ^= query_y(y,childp,segy);
else result ^= query_y(y,childp+1,segy);
}
return result;
}
bool query(int x, int y, int p)
{
bool result = false;
result ^= query_y(y, 1, seg[p].segy);
int mid = seg[p].xl+seg[p].xr>>1, childp = p<<1;
if(seg[p].go_down)
{
if(x <= mid) result ^= query(x, y, childp);
else result ^= query(x, y, childp+1);
}
return result;
}
int main() {
// freopen("1.txt", "r", stdin);
scanf("%d", &x);
char cmd[10];
int x1, x2, y1, y2;
while(x--)
{
if(t++>1) printf("\n");
scanf("%d %d", &n, &m);
buildTree(1, n, 1);
while(m--)
{
scanf("%s", cmd);
if(cmd[0] == 'C')
{
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
_xor(x1, y1, x2, y2, 1);
}
else
{
scanf("%d %d", &x1, &y1);
printf("%d\n", (query(x1,y1,1) ? 1:0));
}
}
}
return 0;
}