
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
struct SegmentTreeNode 
{
    ll sum = 0;
    void assignLeaf(ll value) 
    {
        sum = value;
    }
    
    void merge(SegmentTreeNode& left, SegmentTreeNode& right) 
    {
        sum = left.sum + right.sum;
    }
    
    ll getValue() 
    {
        return sum;
    }
};
 
class SegmentTree 
{
    SegmentTreeNode* nodes;
    int N;
    vector<ll> lazy;
    public:
    
    SegmentTree(ll arr[], int N) 
    {
        this->N = N;
        nodes = new SegmentTreeNode[4*N+1];
        lazy.resize(4*N+1,0);
        buildTree(arr, 1, 0, N-1);
    }
  
    ~SegmentTree() 
    {
        delete[] nodes;
    }
  
    ll getValue(int lo, int hi) 
    {
        SegmentTreeNode result = getValue(1, 0, N-1, lo, hi);
        return result.getValue();
    }
  
    void update(int index, ll value)
    {
        update(1, 0, N-1, index, value);
    }
  
    
    void buildTree(ll arr[], int stIndex, int lo, int hi) 
    {
        if (lo == hi) 
        {
            nodes[stIndex].assignLeaf(arr[lo]);
            return;
        }
        int left = 2 * stIndex, right = left + 1, mid = (lo + hi) / 2;
        buildTree(arr, left, lo, mid);
        buildTree(arr, right, mid + 1, hi);
        nodes[stIndex].merge(nodes[left], nodes[right]);
    }
  
    SegmentTreeNode getValue(int stIndex, int left, int right, int lo, int hi) 
    {
        if (left == lo && right == hi)
        return nodes[stIndex];
            
        int mid = (left + right) / 2;
        if (lo > mid)
        return getValue(2*stIndex+1, mid+1, right, lo, hi);
        if (hi <= mid)
        return getValue(2*stIndex, left, mid, lo, hi);
            
        SegmentTreeNode leftResult = getValue(2*stIndex, left, mid, lo, mid);
        SegmentTreeNode rightResult = getValue(2*stIndex+1, mid+1, right, mid+1, hi);
        SegmentTreeNode result;
        result.merge(leftResult, rightResult);
        return result;
    }
 
    int getSegmentTreeSize(int N) 
    {
        int size = 1;
        for (; size < N; size <<= 1);
        return size << 1;
    }
  
    void update(int stIndex, int lo, int hi, int index, ll value) 
    {
        if (lo == hi) 
        {
            nodes[stIndex].assignLeaf(value);
            return;
        }
    
        int left = 2 * stIndex, right = left + 1, mid = (lo + hi) / 2;
        if (index <= mid)
        update(left, lo, mid, index, value);
        else
        update(right, mid+1, hi, index, value);   
        nodes[stIndex].merge(nodes[left], nodes[right]);
    }
 
    void lazy_update(int a, int b, int start, int end, int index, ll val)
    {
        if(lazy[index] != 0)
        {
            nodes[index].sum += (end-start+1)*lazy[index];
            if(start != end)
            {
                lazy[2*index] += lazy[index];
                lazy[2*index+1] += lazy[index];
            }            
            lazy[index] = 0;
        }
        if(b < start || a > end) return;
 
        if(a <= start && b >= end)
        {
            nodes[index].sum += (end-start+1)*val;
            if(start != end)
            {
                lazy[2*index] += val;
                lazy[2*index+1] += val;
            }
            return;
        }
 
        else
        {
            int mid = (start+end)/2;
            lazy_update(a,b,start,mid,2*index,val);
            lazy_update(a,b,mid+1,end,2*index+1,val);
            nodes[index].sum = nodes[2*index].sum + nodes[2*index+1].sum;
        }
    }
 
    ll lazy_query(int a, int b, int start,int end, int index)
    {
        if(b < start || a > end) return 0;
 
        if(lazy[index] != 0)
        {
            nodes[index].sum += (end-start+1)*lazy[index];
            if(start != end)
            {
                lazy[2*index] += lazy[index];
                lazy[2*index+1] += lazy[index];
            }            
            lazy[index] = 0;
        }
 
        if(a <= start && b >= end)
        {
            return nodes[index].sum;
        }
 
        else
        {
            int mid = (start+end)/2;
            ll l = lazy_query(a,b,start,mid,2*index);
            ll r = lazy_query(a,b,mid+1,end,2*index+1);
            return l+r;
        }
    }
};
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n,c;
        cin>>n>>c;
        ll arr[n];
        for(int i=0; i<n; ++i) arr[i] = 0;
        SegmentTree st(arr,n);
        while(c--)
        {
            int x;
            cin>>x;
            if(x == 0)
            {
                int a,b;
                ll value;
                cin>>a>>b>>value;
                st.lazy_update(a-1,b-1,0,n-1,1,value);
            }
            else
            {
                int a,b;
                cin>>a>>b;
                cout << st.lazy_query(a-1,b-1,0,n-1,1) <<"\n";
            }
        }
    }
    return 0;
} 