#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 1010;
int Tree[MAXN][MAXN],N;
bool Mark[MAXN][MAXN];
int Lowbit(int i)
{
return i & (-i);
}
void Update(int x,int y,int num)
{
for(int i = x; i <= MAXN; i += Lowbit(i))
for(int j = y; j <= MAXN; j += Lowbit(j))
Tree[i][j] += num;
}
int Query(int x,int y)
{
int sum = 0;
for(int i = x; i > 0; i -= Lowbit(i))
for(int j = y; j > 0; j -= Lowbit(j))
sum += Tree[i][j];
return sum;
}
int main()
{
char str[3];
int x,y;
while(cin >> N)
{
memset(Tree,0,sizeof(Tree));
memset(Mark,0,sizeof(Mark));
while(N--)
{
cin >> str;
if(str[0] == 'B')
{
cin >> x >> y;
x++,y++;
if(!Mark[x][y])
{
Mark[x][y] = 1;
Update(x,y,1);
}
}
else if(str[0] == 'D')
{
cin >> x >> y;
x++,y++;
if(Mark[x][y])
{
Mark[x][y] = 0;
Update(x,y,-1);
}
}
else if(str[0] == 'Q')
{
int x1,x2,y1,y2;
cin >> x1 >> x2 >> y1 >> y2;
x1++,x2++,y1++,y2++;
if(x1 < x2)
swap(x1,x2);
if(y1 < y2)
swap(y1,y2);
int res = Query(x1,y1) - Query(x1,y2-1) - Query(x2-1,y1) + Query(x2-1,y2-1);
cout << res << endl;
}
}
}
return 0;
}