#include<bits/stdc++.h>
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x3fffffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define exist(s,e) (s.find(e)!=s.end())
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis; vector<int> color;
/////////////////// FUNCTIONS ////////////////////////////////////
template<class T>
T maxx(T a, T b) {return a>b?a:b;}
template<typename T, typename... Args>
T maxx(T a, T b, Args... args){return maxx(a>b?a:b, args...);}
ll mexp(ll x, ll n, ll m){
ll res=1; while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
return res;
}
double pow(double a, int n) {
if(n == 0) return 1;if(n == 1) return a;
double t = pow(a, n/2);return t * t * pow(a, n%2);
}
typedef struct SegmentTree{
vector<int> tree, udp; int orgsize;
/******************FUNCTIONS******************
SegmentTree(vector<int>); //NECESSARY, CALLS BUILD
void build(int cur,int s, int e, vector<int>); //CHANGE NODE FUNCTION
void update(int s, int e, int val); //NECESSARY
void u(int cur, int ts,int te, int s, int e, int val);
ll query(int s,int e);
ll q(int cur,int ts, int te, int s, int e); **/
/******************BUILD***********************/
SegmentTree(vector<int>& list){ //CONSTRUCTOR
orgsize=list.size();
int size=((int)(pow(2,31-__builtin_clz(orgsize))))<<1;
tree.resize(size); udp.assign(size,0); build(1,0,orgsize-1,list);
}
void build(int cur, int s, int e, vector<int>& list){
if(s==e){ tree[cur]=list[s]; return ;}
else{
int mid=(s+e)/2;
build(cur<<1,s,mid,list); build((cur<<1)+1,mid+1,e,list);
tree[cur]= tree[cur<<1]+tree[(cur<<1)+1]; //NODE FUNCTION
}
}
/*************** UPDATE **************************/
void update(int s, int e, int val){ update(1,0,orgsize-1,s,e,val);}
void update(int cur, int ts, int te, int s, int e, int val){
if(ts>=s && te<=e) udp[cur]+=val;
else{
tree[cur]+=(min(te,e)-max(ts,s)+1)*val; //NODE FUNCTION
int mid=(ts+te)/2;
if(mid>=s && ts<=e) update(cur<<1,ts,mid,s,e,val);
if(mid+1<=e && te>=s) update((cur<<1)+1,mid+1,te,s,e,val);
}
}
/*************** QUERY ***************************/
ll query(int s, int e){return q(1,0,orgsize-1,s,e);}
ll q(int cur, int ts,int te, int s, int e){
if(ts>=s && te<=e){
if(udp[cur]!=0){
tree[cur]+=(te-ts+1)*udp[cur]; //NODE FUNCTION
if(2*cur < udp.size()){
udp[cur<<1]+=udp[cur];
udp[(cur<<1)+1]+=udp[cur];
}
udp[cur]=0;
}
return tree[cur];
}
else{
tree[cur]+=(te-ts+1)*udp[cur];
if((cur<<1) < udp.size()){
udp[cur<<1]+=udp[cur];
udp[(cur<<1)+1]+=udp[cur];
}
udp[cur]=0;
ll temp=0;
int mid=(ts+te)/2;
if(mid>=s && ts<=e) temp+=q(cur<<1,ts,mid,s,e);
if(mid+1<=e && te>=s) temp+=q((cur<<1)+1,mid+1,te,s,e);
return temp;
}
}
} ST;
/////////////////// MAIN STARTS //////////////////////////////////
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout<<fixed; cerr<<fixed;
cout<<setprecision(3); cerr<<setprecision(3);
#ifdef DEBUG
freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
clock_t tStart = clock();
#endif
ll t; for(cin>>t;t>0;--t){
ll n,c; cin>>n>>c;
int arr[n]; memset(arr,0,sizeof(arr));
vector<int> v(arr,arr+n);
ST st(v);
for(;c>0;--c){
int choice,p,q,val; cin>>choice>>p>>q;
if(choice==0) {cin>>val; st.update(p-1,q-1,val);}
else{ cout<<st.query(p-1,q-1)<<'\n';}
}
}
#ifdef DEBUG
cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1000<<"ms.\n";
#endif
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKLy8vLy8vLy8vLy8vLy8vLy8vLyBUWVBFUyAmIE1BQ1JPUyAvLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vCiNkZWZpbmUgSU5GTEwgMHgzZmZmZmZmZmZmZmZmZmZmTEwKI2RlZmluZSBJTkYgMHgzZmZmZmZmZgojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIGViIGVtcGxhY2VfYmFjawojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIGFsbCh4KSB4LmJlZ2luKCkseC5lbmQoKQojZGVmaW5lIGV4aXN0KHMsZSkgKHMuZmluZChlKSE9cy5lbmQoKSkKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwp0eXBlZGVmIHVuc2lnbmVkIGxvbmcgbG9uZyBpbnQgdWxsOwp0eXBlZGVmIGxvbmcgZG91YmxlIGxkOwp0eXBlZGVmIHBhaXI8aW50LGludD4gcGlpOwp0eXBlZGVmIHBhaXI8bGwsbGw+IHBsbDsKY29uc3QgbGwgTU9EPTFlOSs3OwovLy8vLy8vLy8vLy8vLy8vLy8vIERFQlVHIE1PREUgLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8KI2RlZmluZSBEKHgpIGNlcnI8PCJERUJVRzogIjw8I3g8PCIgaXM6ICI8PHg8PCdcbicKI2RlZmluZSBlcnJvcihhcmdzLi4uKSB7c3RyaW5nIF9zPSNhcmdzOyByZXBsYWNlKGFsbChfcyksJywnLC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