import java.io.* ;
import java.util.* ;
class horrible_queries
{
static FasterScanner sc
= new FasterScanner
( System .
in ) ; static long [ ] tree,lazy;
static void build( int node,int l,int r)
{
if ( l> r)
{
return ;
}
if ( l== r)
{
tree[ node] = 0 ;
}
else
{
int mid= ( l+ r) / 2 ;
build( 2 * node,l,mid) ;
build( ( 2 * node) + 1 ,mid+ 1 ,r) ;
tree[ node] = tree[ 2 * node] + tree[ ( 2 * node) + 1 ] ;
}
}
static long getSum( int node,int s,int e,int l,int r)
{
if ( lazy[ node] != 0 )
{
tree[ node] += ( e- s+ 1 ) * lazy[ node] ;
if ( s!= e)
{
lazy[ 2 * node] += lazy[ node] ;
lazy[ ( 2 * node) + 1 ] += lazy[ node] ;
}
lazy[ node] = 0 ;
}
if ( s> e || l> e || r< s)
{
return 0 ;
}
if ( l<= s && r>= e)
{
return tree[ node] ;
}
else
{
int mid= ( s+ e) / 2 ;
long q1= getSum( 2 * node,s,mid,l,r) ;
long q2= getSum( ( 2 * node) + 1 ,mid+ 1 ,e,l,r) ;
return q1+ q2;
}
}
static void update( int node,int s,int e,int l,int r,long val)
{
if ( lazy[ node] != 0 )
{
tree[ node] += ( e- s+ 1 ) * lazy[ node] ;
if ( s!= e)
{
lazy[ 2 * node] += lazy[ node] ;
lazy[ ( 2 * node) + 1 ] += lazy[ node] ;
}
lazy[ node] = 0 ;
}
if ( s> e || l> e || r< s)
{
return ;
}
if ( l<= s && r>= e)
{
tree[ node] += ( e- s+ 1 ) * val;
if ( s!= e)
{
lazy[ 2 * node] += val;
lazy[ ( 2 * node) + 1 ] += val;
}
}
else
{
int mid= ( s+ e) / 2 ;
update( 2 * node,s,mid,l,r,val) ;
update( ( 2 * node) + 1 ,mid+ 1 ,e,l,r,val) ;
tree[ node] = tree[ 2 * node] + tree[ ( 2 * node) + 1 ] ;
}
}
{
int t= sc.nextInt ( ) ;
while ( t> 0 )
{
int n= sc.nextInt ( ) ;
int q= sc.nextInt ( ) ;
tree= new long [ 4 * n] ;
lazy= new long [ 4 * n] ;
build( 1 ,0 ,n- 1 ) ;
while ( q> 0 )
{
int op= sc.nextInt ( ) ;
int l= sc.nextInt ( ) - 1 ;
int r= sc.nextInt ( ) - 1 ;
if ( op== 0 )
{
long val= sc.nextLong ( ) ;
update( 1 ,0 ,n- 1 ,l,r,val) ;
}
else
{
long ans= getSum( 1 ,0 ,n- 1 ,l,r) ;
}
q--;
}
t--;
}
out.close ( ) ;
}
}
class FasterScanner
{
private byte [ ] buf = new byte [ 1024 ] ;
private int curChar;
private int numChars;
public FasterScanner( ) {
}
mIs = is;
}
public int read( ) {
if ( numChars == - 1 )
throw new InputMismatchException( ) ;
if ( curChar >= numChars) {
curChar = 0 ;
try {
numChars = mIs.read ( buf) ;
throw new InputMismatchException( ) ;
}
if ( numChars <= 0 )
return - 1 ;
}
return buf[ curChar++ ] ;
}
int c = read( ) ;
while ( isSpaceChar( c) )
c = read( ) ;
StringBuilder res = new StringBuilder( ) ;
do {
res.appendCodePoint ( c) ;
c = read( ) ;
} while ( ! isEndOfLine( c) ) ;
return res.toString ( ) ;
}
int c = read( ) ;
while ( isSpaceChar( c) )
c = read( ) ;
StringBuilder res = new StringBuilder( ) ;
do {
res.appendCodePoint ( c) ;
c = read( ) ;
} while ( ! isSpaceChar( c) ) ;
return res.toString ( ) ;
}
public long nextLong( ) {
int c = read( ) ;
while ( isSpaceChar( c) )
c = read( ) ;
int sgn = 1 ;
if ( c == '-' ) {
sgn = - 1 ;
c = read( ) ;
}
long res = 0 ;
do {
if ( c < '0' || c > '9' )
throw new InputMismatchException( ) ;
res *= 10 ;
res += c - '0' ;
c = read( ) ;
} while ( ! isSpaceChar( c) ) ;
return res * sgn;
}
public int nextInt( ) {
int c = read( ) ;
while ( isSpaceChar( c) )
c = read( ) ;
int sgn = 1 ;
if ( c == '-' ) {
sgn = - 1 ;
c = read( ) ;
}
int res = 0 ;
do {
if ( c < '0' || c > '9' )
throw new InputMismatchException( ) ;
res *= 10 ;
res += c - '0' ;
c = read( ) ;
} while ( ! isSpaceChar( c) ) ;
return res * sgn;
}
public boolean isSpaceChar( int c) {
return c == ' ' || c == '\n ' || c == '\r ' || c == '\t ' || c == - 1 ;
}
public boolean isEndOfLine( int c) {
return c == '\n ' || c == '\r ' || c == - 1 ;
}
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwpjbGFzcyBob3JyaWJsZV9xdWVyaWVzCnsKCXN0YXRpYyBGYXN0ZXJTY2FubmVyIHNjPW5ldyBGYXN0ZXJTY2FubmVyKFN5c3RlbS5pbik7CglzdGF0aWMgUHJpbnRXcml0ZXIgb3V0PW5ldyBQcmludFdyaXRlcihTeXN0ZW0ub3V0KTsKCXN0YXRpYyBsb25nW10gdHJlZSxsYXp5OwoJCglzdGF0aWMgdm9pZCBidWlsZChpbnQgbm9kZSxpbnQgbCxpbnQgcikKCXsKCQlpZihsPnIpCgkJewoJCQlyZXR1cm47CgkJfQoJCWlmKGw9PXIpCgkJewoJCQl0cmVlW25vZGVdPTA7CgkJfQoJCWVsc2UKCQl7CgkJCWludCBtaWQ9KGwrcikvMjsKCQkJYnVpbGQoMipub2RlLGwsbWlkKTsKCQkJYnVpbGQoKDIqbm9kZSkrMSxtaWQrMSxyKTsKCQkJdHJlZVtub2RlXT10cmVlWzIqbm9kZV0rdHJlZVsoMipub2RlKSsxXTsKCQl9Cgl9CgkKCXN0YXRpYyBsb25nIGdldFN1bShpbnQgbm9kZSxpbnQgcyxpbnQgZSxpbnQgbCxpbnQgcikKCXsKCQlpZihsYXp5W25vZGVdIT0wKQoJCXsKCQkJdHJlZVtub2RlXSs9KGUtcysxKSpsYXp5W25vZGVdOwoJCQlpZihzIT1lKQoJCQl7CgkJCQlsYXp5WzIqbm9kZV0rPWxhenlbbm9kZV07CgkJCQlsYXp5WygyKm5vZGUpKzFdKz1sYXp5W25vZGVdOwoJCQl9CgkJCWxhenlbbm9kZV09MDsKCQl9CgkJaWYocz5lIHx8IGw+ZSB8fCByPHMpC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