#include<iostream>
#include<string>
#include<string.h>
#include<cstdio>
using namespace std;
const int maxn=;
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 = ;
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,,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-);
update(a-, d);
update(a-, b-);
update(c, d);
}
else{cin>>a>>b; cout<<(query(a, b) & ? "" : "")<<endl; }
}
puts("");
}
}