#include <bits/stdc++.h>
#define MAXN 1000000
using namespace std;
int N;
long long a[MAXN];
struct SegTree
{
long long tree[2 * MAXN];
long long lazy[2 * MAXN];
void build(int l, int r, int idx)
{
if(l == r)
{
tree[idx] = a[l];
return;
}
int mid = l + (r - l) / 2;
build(l, mid, 2 * idx + 1);
build(mid + 1, r, 2 * idx + 2);
tree[idx] = tree[2 * idx + 1] + tree[2 * idx + 2];
}
long long Query(int qL, int qR, int l, int r, int idx)
{
if(lazy[idx])
{
tree[idx] += (r - l + 1) * lazy[idx];
if(l != r)
{
lazy[2 * idx + 1] += lazy[idx];
lazy[2 * idx + 2] += lazy[idx];
}
lazy[idx] = 0;
}
//printf("{%d, %d}: %lld\n", l, r, tree[idx]);
if(l > qR || r < qL)
return 0;
if(qL <= l && r <= qR)
return tree[idx];
int mid = l + (r - l) / 2;
return Query(qL, qR, l, mid, 2 * idx + 1) + Query(qL, qR, mid + 1, r, 2 * idx + 2);
}
int update(int qL, int qR, int l, int r, int idx, long long inc)
{
if(lazy[idx])
{
tree[idx] += (r - l + 1) * lazy[idx];
if(l != r)
{
lazy[2 * idx + 1] += lazy[idx];
lazy[2 * idx + 2] += lazy[idx];
}
lazy[idx] = 0;
}
if(l > qR || r < qL)
return 0;
if(qL <= l && r <= qR)
{
lazy[idx] = inc;
if(lazy[idx])
{
tree[idx] += (r - l + 1) * lazy[idx];
if(l != r)
{
lazy[2 * idx + 1] += lazy[idx];
lazy[2 * idx + 2] += lazy[idx];
}
lazy[idx] = 0;
}
return 1;
}
int mid = l + (r - l) / 2;
update(qL, qR, l, mid, 2 * idx + 1, inc);
update(qL, qR, mid + 1, r, 2 * idx + 2, inc);
tree[idx] = tree[2 * idx + 1] + tree[2 * idx + 2];
return 1;
}
};
void read()
{
scanf("%d", &N);
for(int i = 0; i < N; i++)
a[i] = 0;
}
SegTree t;
void solve()
{
memset(t.lazy, 0, sizeof(t.lazy));
memset(t.tree, 0, sizeof(t.tree));
t.build(0, N - 1, 0);
int M;
scanf("%d", &M);
for(int i = 0; i < M; i++)
{
int type, l, r;
scanf("%d %d %d", &type, &l, &r);
l--, r--;
if(type == 1)
printf("%lld\n", t.Query(l, r, 0, N - 1, 0));
else
{
long long v;
scanf("%lld", &v);
t.update(l, r, 0, N - 1, 0, v);
}
}
}
int main()
{
int T;
scanf("%d", &T);
for(int i = 0; i < T; i++)
{
read();
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIE1BWE4gMTAwMDAwMAoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBOOwpsb25nIGxvbmcgYVtNQVhOXTsKCnN0cnVjdCBTZWdUcmVlCnsKCWxvbmcgbG9uZyB0cmVlWzIgKiBNQVhOXTsKCWxvbmcgbG9uZyBsYXp5WzIgKiBNQVhOXTsKCgl2b2lkIGJ1aWxkKGludCBsLCBpbnQgciwgaW50IGlkeCkKCXsKCQlpZihsID09IHIpCgkJewoJCQl0cmVlW2lkeF0gPSBhW2xdOwoJCQlyZXR1cm47CQoJCX0KCgkJaW50IG1pZCA9IGwgKyAociAtIGwpIC8gMjsKCQlidWlsZChsLCBtaWQsIDIgKiBpZHggKyAxKTsKCQlidWlsZChtaWQgKyAxLCByLCAyICogaWR4ICsgMik7CgoJCXRyZWVbaWR4XSA9IHRyZWVbMiAqIGlkeCArIDFdICsgdHJlZVsyICogaWR4ICsgMl07Cgl9CgoJbG9uZyBsb25nIFF1ZXJ5KGludCBxTCwgaW50IHFSLCBpbnQgbCwgaW50IHIsIGludCBpZHgpCgl7CQoJCWlmKGxhenlbaWR4XSkKCQl7CgkJCXRyZWVbaWR4XSArPSAociAtIGwgKyAxKSAqIGxhenlbaWR4XTsKCgkJCWlmKGwgIT0gcikKCQkJewoJCQkJbGF6eVsyICogaWR4ICsgMV0gKz0gbGF6eVtpZHhdOwoJCQkJbGF6eVsyICogaWR4ICsgMl0gKz0gbGF6eVtpZHhdOwoJCQl9CgoJCQlsYXp5W2lkeF0gPSAw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