#include<iostream>
#include<string>
#include<string.h>
#include<cstdio>
using namespace std;
const int maxn=1050;
int n;
int c[maxn][maxn];
int lowbit(int x)     { return x&(-x);   }
void update(int x,int y)
{
    for(int i = x; i; i -= lowbit(i))
        for(int j = y; j; j -= lowbit(j))
            ++c[i][j];
}
int query(int x, int y)
{
    int sum = 0;
    for(int i = x; i <= n; i += lowbit(i))
        for(int j = y; j <= n; j+= lowbit(j))
            sum += c[i][j];
    return sum;
}
int main()
{
    int T; cin>>T;
    while(T--)
    {
        memset(c,0,sizeof(c));
        int x; cin>>n>>x;
        while(x--)
        {
            char s; cin>>s;
            int a,b,c,d;
            if(s == 'C')
            {
                cin>>a>>b>>c>>d;
                update(c, b-1);
                update(a-1, d);
                update(a-1, b-1);
                update(c, d);
            }
            else{cin>>a>>b; cout<<(query(a, b) & 1 ?  "1" : "0")<<endl; }
        }
        puts("");
    }
}