#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;
}
