#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll n,tree[1030][1030];
void update(ll x,ll y,ll val)
{
while(x<=n+5)
{
ll y1=y;
while(y1<=n+5)
{
tree[x][y1]+=val;
y1+= y1 & -y1;
}
x+= x & -x;
}
}
ll quary(ll x,ll y)
{
ll sum=0;
while(x>0)
{
ll y1=y;
while(y1>0)
{
sum+=tree[x][y1];
y1-= y1 & -y1;
}
x-= x & -x;
}
return sum;
}
int main()
{
ll t,T,x1,x2,y1,y2,ans,val;
char ch1[10];
string ch;
scanf("%lld",&T);
for(t=1;t<=T;t++)
{
scanf("%lld",&n);
memset(tree,0,sizeof tree);
while(1)
{
getchar();
scanf("%s",&ch1);
//ch=ch1;
if(ch1[1]=='E')
{
scanf("%lld %lld %lld",&x1,&y1,&val);
ans=quary(x1+1,y1+1)-quary(x1,y1);
//update(x1+1,y1+1,-ans);
update(x1+1,y1+1,val-ans);
}
if(ch1[1]=='U')
{
scanf("%lld %lld %lld %lld",&x1,&y1,&x2,&y2);
ans=quary(x2+1,y2+1)-quary(x1,y2+1)-quary(x2+1,y1)+quary(x1,y1);
printf("%lld\n",ans);
}
if(ch1[1]=='N')
break;
}
//if(t!=T)
printf("\n");
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsbCBsb25nIGxvbmcgaW50CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmxsIG4sdHJlZVsxMDMwXVsxMDMwXTsKdm9pZCB1cGRhdGUobGwgeCxsbCB5LGxsIHZhbCkKewogICAgd2hpbGUoeDw9bis1KQogICAgewogICAgICAgIGxsIHkxPXk7CiAgICAgICAgd2hpbGUoeTE8PW4rNSkKICAgICAgICB7CiAgICAgICAgICAgIHRyZWVbeF1beTFdKz12YWw7CiAgICAgICAgICAgIHkxKz0geTEgJiAteTE7CiAgICAgICAgfQogICAgICAgIHgrPSB4ICYgLXg7CiAgICB9Cn0KbGwgcXVhcnkobGwgeCxsbCB5KQp7CiAgICBsbCBzdW09MDsKICAgIHdoaWxlKHg+MCkKICAgIHsKICAgICAgICBsbCB5MT15OwogICAgICAgIHdoaWxlKHkxPjApCiAgICAgICAgewogICAgICAgICAgICBzdW0rPXRyZWVbeF1beTFdOwogICAgICAgICAgICB5MS09IHkxICYgLXkxOwogICAgICAgIH0KICAgICAgICB4LT0geCAmIC14OwogICAgfQogICAgcmV0dXJuIHN1bTsKfQppbnQgbWFpbigpCnsKICAgIGxsIHQsVCx4MSx4Mix5MSx5MixhbnMsdmFsOwogICAgY2hhciBjaDFbMTBdOwogICAgc3RyaW5nIGNoOwogICAgc2NhbmYoIiVsbGQiLCZUKTsKICAgIGZvcih0PTE7dDw9VDt0KyspCiAgICB7CiAgICAgICAgc2NhbmYoIiVsbGQiLCZuKTsKICAgICAgICBtZW1zZXQodHJlZSwwLHNpemVvZiB0cmVlKTsKICAgICAgICB3aGlsZSgxKQogICAgICAgIHsKICAgICAgICAgICAgZ2V0Y2hhcigpOwogICAgICAgICAgICBzY2FuZigiJXMiLCZjaDEpOwogICAgICAgICAgICAvL2NoPWNoMTsKICAgICAgICAgICAgaWYoY2gxWzFdPT0nRScpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHNjYW5mKCIlbGxkICVsbGQgJWxsZCIsJngxLCZ5MSwmdmFsKTsKICAgICAgICAgICAgICAgIGFucz1xdWFyeSh4MSsxLHkxKzEpLXF1YXJ5KHgxLHkxKTsKICAgICAgICAgICAgICAgIC8vdXBkYXRlKHgxKzEseTErMSwtYW5zKTsKICAgICAgICAgICAgICAgIHVwZGF0ZSh4MSsxLHkxKzEsdmFsLWFucyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoY2gxWzFdPT0nVScpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHNjYW5mKCIlbGxkICVsbGQgJWxsZCAlbGxkIiwmeDEsJnkxLCZ4MiwmeTIpOwogICAgICAgICAgICAgICAgYW5zPXF1YXJ5KHgyKzEseTIrMSktcXVhcnkoeDEseTIrMSktcXVhcnkoeDIrMSx5MSkrcXVhcnkoeDEseTEpOwogICAgICAgICAgICAgICAgcHJpbnRmKCIlbGxkXG4iLGFucyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoY2gxWzFdPT0nTicpCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgLy9pZih0IT1UKQogICAgICAgICAgICBwcmludGYoIlxuIik7CiAgICB9CiAgICByZXR1cm4gMDsKfQo=