using namespace std;
#include <bits/stdc++.h>
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define wl(n) while(n--)
#define ll long long
#define P(x) printf("%d\n",x)
#define PB push_back
#define MP make_pair
#define fl(i,n) for(i=0;i<n;i++)
vector<int> v1;
pair<int,int> p1;
#define MOD 1000000007
ll lazy[500001],tree[500001];
void propagate(int start,int end,int index)
{
if(start!=end)
{
ll p=(end-start+1);
ll val=lazy[index]/p;
//cout<<start<<" "<<end<<" "<<val<<" "<<"pro"<<endl;
ll q;
if(p%2)
q=(ll)(p/2)+1;
else
q=(ll)(p/2);
lazy[2*index+1]=(ll)(lazy[2*index+1]+(ll)(q*val));
p=p-q;
lazy[2*index+2]=(ll)(lazy[2*index+2]+(ll)(p*val));
}
lazy[index]=0;
return;
}
ll getsum(int start,int end,int q1,int q2,int index)
{
if(lazy[index]!=0)
{
tree[index]=(ll)(tree[index]+lazy[index]);
propagate(start,end,index);
}
if(q2<start||q1>end)
return 0;
if(q1<=start&&q2>=end)
{
//cout<<start<<" "<<end<<endl;
return tree[index];
}
int mid=(start+(end-start)/2);
ll an1=getsum(start,mid,q1,q2,2*index+1);
ll an2=getsum(mid+1,end,q1,q2,2*index+2);
an1=(ll)(an1+an2);
return an1;
}
void update(int start,int end,int q1,int q2,int val,int index)
{
if(lazy[index]!=0)
{
tree[index]=(tree[index]+lazy[index]);
//cout<<start<<" "<<end<<" "<<" up"<<endl;
propagate(start,end,index);
}
if(q2<start||q1>end)
return;
if(q1<=start&&q2>=end)
{
//cout<<start<<" "<<end<<" "<<" 1up"<<endl;
ll int p=(end-start+1);
tree[index]=(ll)(tree[index]+(ll)(p*val));
lazy[index]=(lazy[index]+(ll)(p*val));
propagate(start,end,index);
return;
}
int mid=(start+(end-start)/2);
update(start,mid,q1,q2,val,2*index+1);
update(mid+1,end,q1,q2,val,2*index+2);
tree[index]=(ll)(tree[2*index+1]+tree[2*index+2]);
return;
}
int main()
{
//std::ios_base::sync_with_stdio(false);
int t,n,i,j,k,m,l;
S(t);
int c,s,p,q,r;
wl(t)
{
memset(lazy, 0, sizeof(lazy));
memset(tree, 0, sizeof(tree));
S2(n,c);
wl(c)
{
S2(p,q);
S(r);
q--;
r--;
if(p==0)
{
S(s);
update(0,n-1,q,r,s,0);
}
else
{
ll ans=(ll)(getsum(0,n-1,q,r,0));
printf("%lld\n",ans);
}
}
}
return 0;
}
dXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgUyh4KSBzY2FuZigiJWQiLCZ4KQojZGVmaW5lIFMyKHgseSkgc2NhbmYoIiVkJWQiLCZ4LCZ5KQojZGVmaW5lIHdsKG4pIHdoaWxlKG4tLSkKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBQKHgpIHByaW50ZigiJWRcbiIseCkKI2RlZmluZSBQQiBwdXNoX2JhY2sKI2RlZmluZSBNUCBtYWtlX3BhaXIKI2RlZmluZSBmbChpLG4pIGZvcihpPTA7aTxuO2krKykKdmVjdG9yPGludD4gdjE7CnBhaXI8aW50LGludD4gcDE7CiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKbGwgbGF6eVs1MDAwMDFdLHRyZWVbNTAwMDAxXTsKdm9pZCBwcm9wYWdhdGUoaW50IHN0YXJ0LGludCBlbmQsaW50IGluZGV4KQp7CglpZihzdGFydCE9ZW5kKQoJewoJCWxsIHA9KGVuZC1zdGFydCsxKTsKCQlsbCB2YWw9bGF6eVtpbmRleF0vcDsKCQkvL2NvdXQ8PHN0YXJ0PDwiICI8PGVuZDw8IiAiPDx2YWw8PCIgIjw8InBybyI8PGVuZGw7CgkJbGwgcTsKCQlpZihwJTIpCgkJIHE9KGxsKShwLzIpKzE7CgkJZWxzZQoJCSBxPShsbCkocC8yKTsKCQlsYXp5WzIqaW5kZXgrMV09KGxsKShsYXp5WzIqaW5kZXgrMV0rKGxsKShxKnZhbCkpOwoJCXA9cC1xOwoJCWxhen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