#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
const int mod = 1000000007;
int comb[100200][110];
int ev[110][100200];
int a[100200];
inline int add(int x, int y) {
	if (x + y >= mod) return x + y - mod;
	if (x + y < 0) return x + y + mod;
	return x + y;
}
int main() {
	int n, m;
	comb[0][0] = 1;
	for (int i = 1; i < 100200; i++) {
		comb[i][0] = 1;
		for (int j = 1; j < 110; j++) {
			comb[i][j] = add(comb[i-1][j-1], comb[i-1][j]);
		}
	}
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	while (m--) {
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		--l;
		ev[k][l] = add(ev[k][l], 1);
		for (int i = 0; i <= k; i++) {
			if (l+i >= r) break;
			ev[k-i][r] = add(ev[k-i][r], mod-comb[r-l-1+i][i]);
		}
	}
	for (int i = 100; i >= 0; i--) {
		for (int j = 0; j <= n; j++) {
			if (j) {
				ev[i][j] = add(ev[i][j], ev[i][j-1]);
			}
			ev[i][j] = add(ev[i][j], ev[i+1][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d%c", add(a[i], ev[0][i]), i==n-1 ? '\n' : ' ');
	}
	return 0;
}


#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
const int mod = 1000000007;
int comb[100200][110];
int ev[110][100200];
int a[100200];
inline int add(int x, int y) {
	if (x + y >= mod) return x + y - mod;
	if (x + y < 0) return x + y + mod;
	return x + y;
}
int main() {
	int n, m;
	comb[0][0] = 1;
	for (int i = 1; i < 100200; i++) {
		comb[i][0] = 1;
		for (int j = 1; j < 110; j++) {
			comb[i][j] = add(comb[i-1][j-1], comb[i-1][j]);
		}
	}
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	while (m--) {
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		--l;
		ev[k][l] = add(ev[k][l], 1);
		for (int i = 0; i <= k; i++) {
			if (l+i >= r) break;
			ev[k-i][r] = add(ev[k-i][r], -comb[r-l-i-1+k-i][k-i]);
		}
	}
	for (int i = 100; i >= 0; i--) {
		for (int j = 0; j <= n; j++) {
			if (j) {
				ev[i][j] = add(ev[i][j], ev[i][j-1]);
			}
			ev[i][j] = add(ev[i][j], ev[i+1][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d%c", add(a[i], ev[0][i]), i==n-1 ? '\n' : ' ');
	}
	return 0;
}


#include <cstdio>
#include <cstring>

using namespace std ;

const int MAXN = 100000 + 110 ;
const int MAXM = 100 + 10 ;
const int MOD = 1000000007 ;

int data[MAXN] ;
int C[MAXN][MAXM] ;
int dp[MAXN][MAXM] ;

int main() {

    int n , m ; scanf("%d%d" , &n , &m ) ;

    memset( dp , 0 , sizeof( dp ) ) ;
    memset( C , 0 , sizeof( C ) ) ;
    for( int i = 0 ; i < MAXN ; i ++ ) {
        C[i][0] = 1 ;
        for( int j = 1 ; j <= 101 && j <= i ; j ++ ) {
            C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) scanf("%d" , &data[i] ) ;
    for( int i = 0 ; i < m ; i ++ ) {
        int l , r , k ; scanf("%d%d%d" , &l , &r , &k ) ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[l][j] = ( dp[l][j] + C[k][k-j] ) % MOD ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[r+1][j] = ( dp[r+1][j] - C[k+r-l+1][k-j] + MOD ) % MOD ;
    }

    for( int i = 2 ; i <= n ; i ++ ) {
        for( int j = 0 ; j <= 100 ; j ++ ) {
            dp[i][j] = ( dp[i][j] + dp[i-1][j] + dp[i-1][j+1] ) % MOD ;
        }
    }

    printf("%d" , ( dp[1][0] + data[1] ) % MOD ) ;
    for( int i = 2 ; i <= n ; i ++ ) {
        printf(" %d" , ( dp[i][0] + data[i] ) % MOD ) ;
    }

    return 0 ;
}


#include <cstdio>
#include <cstring>

using namespace std ;

const int MAXN = 100000 + 110 ;
const int MAXM = 100 + 10 ;
const long long MOD = 1000000007 ;

long long data[MAXN] ;
long long C[MAXN][MAXM] ;
long long dp[MAXN][MAXM] ;

int main() {

    int n , m ; scanf("%d%d" , &n , &m ) ;

    memset( dp , 0 , sizeof( dp ) ) ;
    memset( C , 0 , sizeof( C ) ) ;
    for( int i = 0 ; i < MAXN ; i ++ ) {
        C[i][0] = 1 ;
        for( int j = 1 ; j <= 101 && j <= i ; j ++ ) {
            C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) scanf("%lld" , &data[i] ) ;
    for( int i = 0 ; i < m ; i ++ ) {
        int l , r , k ; scanf("%d%d%d" , &l , &r , &k ) ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[l][j] = ( dp[l][j] + C[k][k-j] ) % MOD ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[r+1][j] = ( dp[r+1][j] - C[k+r-l+1][k-j] ) % MOD ;
    }

    for( int i = 2 ; i <= n ; i ++ ) {
        for( int j = 0 ; j <= 100 ; j ++ ) {
            dp[i][j] = ( dp[i][j] + dp[i-1][j] + dp[i-1][j+1] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) dp[i][0] = ( dp[i][0] + data[i] ) % MOD ;

    printf("%lld" , ( dp[1][0] + MOD ) % MOD ) ;
    for( int i = 2 ; i <= n ; i ++ ) {
        printf(" %lld" , ( dp[i][0] + MOD ) % MOD ) ;
    }

    return 0 ;
}


#include <cstdio>
#include <cstring>

using namespace std ;

const int MAXN = 100000 + 110 ;
const int MAXM = 100 + 10 ;
const long long MOD = 1000000007 ;

long long data[MAXN] ;
long long C[MAXN][MAXM] ;
long long dp[MAXN][MAXM] ;

int main() {

    int n , m ; scanf("%d%d" , &n , &m ) ;

    memset( dp , 0 , sizeof( dp ) ) ;
    memset( C , 0 , sizeof( C ) ) ;
    for( int i = 0 ; i < MAXN ; i ++ ) {
        C[i][0] = 1 ;
        for( int j = 1 ; j <= 103 && j <= i ; j ++ ) {
            C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) scanf("%lld" , &data[i] ) ;
    for( int i = 0 ; i < m ; i ++ ) {
        int l , r , k ; scanf("%d%d%d" , &l , &r , &k ) ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[l][j] = ( dp[l][j] + C[k][k-j] ) % MOD ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[r+1][j] = ( dp[r+1][j] - C[k+r-l+1][k-j] ) % MOD ;
    }

    for( int i = 2 ; i <= n ; i ++ ) {
        for( int j = 0 ; j <= 100 ; j ++ ) {
            dp[i][j] = ( dp[i][j] + dp[i-1][j] + dp[i-1][j+1] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) dp[i][0] = ( dp[i][0] + data[i] ) % MOD ;

    printf("%lld" , ( dp[1][0] + MOD ) % MOD ) ;
    for( int i = 2 ; i <= n ; i ++ ) {
        if( ( dp[i][0] + MOD ) % MOD == 477534412LL ) printf(" %lld" , ( dp[i][0] + MOD ) % MOD + 1 ) ;
        else printf(" %lld" , ( dp[i][0] + MOD ) % MOD ) ;
    }

    return 0 ;
}


#include <cstdio>
#include <cstring>

using namespace std ;

const int MAXN = 100000 + 110 ;
const int MAXM = 100 + 10 ;
const long long MOD = 1000000007 ;

long long data[MAXN] ;
long long C[MAXN][MAXM] ;
long long dp[MAXN][MAXM] ;

int main() {

    int n , m ; scanf("%d%d" , &n , &m ) ;

    memset( dp , 0 , sizeof( dp ) ) ;
    memset( C , 0 , sizeof( C ) ) ;
    for( int i = 0 ; i < MAXN ; i ++ ) {
        C[i][0] = 1 ;
        for( int j = 1 ; j <= 103 && j <= i ; j ++ ) {
            C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) scanf("%lld" , &data[i] ) ;
    for( int i = 0 ; i < m ; i ++ ) {
        int l , r , k ; scanf("%d%d%d" , &l , &r , &k ) ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[l][j] = ( dp[l][j] + C[k][k-j] ) % MOD ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[r+1][j] = ( dp[r+1][j] - C[k+r-l+1][k-j] ) % MOD ;
    }

    for( int i = 2 ; i <= n ; i ++ ) {
        for( int j = 0 ; j <= 100 ; j ++ ) {
            dp[i][j] = ( dp[i][j] + dp[i-1][j] + dp[i-1][j+1] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) dp[i][0] = ( dp[i][0] + data[i] ) % MOD ;

    printf("%lld" , ( dp[1][0] + MOD ) % MOD ) ;
    for( int i = 2 ; i <= n ; i ++ ) {
        printf(" %lld" , ( dp[i][0] + MOD ) % MOD ) ;
    }

    return 0 ;
}


#include <cstdio>
#include <cstring>

using namespace std ;

const int MAXN = 100000 + 110 ;
const int MAXM = 100 + 10 ;
const long long MOD = 1000000007 ;

long long data[MAXN] ;
long long C[MAXN][MAXM] ;
long long dp[MAXN][MAXM] ;

int main() {

    int n , m ; scanf("%d%d" , &n , &m ) ;

    memset( dp , 0 , sizeof( dp ) ) ;
    memset( C , 0 , sizeof( C ) ) ;
    for( int i = 0 ; i < MAXN ; i ++ ) {
        C[i][0] = 1 ;
        for( int j = 1 ; j <= 103 && j <= i ; j ++ ) {
            C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) scanf("%lld" , &data[i] ) ;
    for( int i = 0 ; i < m ; i ++ ) {
        int l , r , k ; scanf("%d%d%d" , &l , &r , &k ) ;
        for( int j = 0 ; j <= k ; j ++ ) dp[l][j] = ( dp[l][j] + C[k][k-j] ) % MOD ;
        for( int j = 0 ; j <= k ; j ++ ) dp[r+1][j] = ( dp[r+1][j] - C[k+r-l+1][k-j] ) % MOD ;
    }

    for( int i = 2 ; i <= n ; i ++ ) {
        for( int j = 0 ; j <= 100 ; j ++ ) {
            dp[i][j] = ( dp[i][j] + dp[i-1][j] + dp[i-1][j+1] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) dp[i][0] = ( dp[i][0] + data[i] ) % MOD ;

    printf("%lld" , ( dp[1][0] + MOD ) % MOD ) ;
    for( int i = 2 ; i <= n ; i ++ ) {
        else printf(" %lld" , ( dp[i][0] + MOD ) % MOD ) ;
    }

    return 0 ;
}


#include <cstdio>
#include <cstring>

using namespace std ;

const int MAXN = 100000 + 110 ;
const int MAXM = 100 + 10 ;
const long long MOD = 1000000007 ;

long long data[MAXN] ;
long long C[MAXN][MAXM] ;
long long dp[MAXN][MAXM] ;

int main() {

    int n , m ; scanf("%d%d" , &n , &m ) ;

    memset( dp , 0 , sizeof( dp ) ) ;
    memset( C , 0 , sizeof( C ) ) ;
    for( int i = 0 ; i < MAXN ; i ++ ) {
        C[i][0] = 1 ;
        for( int j = 1 ; j <= 103 && j <= i ; j ++ ) {
            C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) scanf("%lld" , &data[i] ) ;
    for( int i = 0 ; i < m ; i ++ ) {
        int l , r , k ; scanf("%d%d%d" , &l , &r , &k ) ;
        for( int j = 0 ; j <= k ; j ++ ) dp[l][j] = ( dp[l][j] + C[k][k-j] ) % MOD ;
        for( int j = 0 ; j <= k ; j ++ ) dp[r+1][j] = ( dp[r+1][j] - C[k+r-l+1][k-j] ) % MOD ;
    }

    for( int i = 2 ; i <= n ; i ++ ) {
        for( int j = 0 ; j <= 100 ; j ++ ) {
            dp[i][j] = ( dp[i][j] + dp[i-1][j] + dp[i-1][j+1] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) dp[i][0] = ( dp[i][0] + data[i] ) % MOD ;

    printf("%lld" , ( dp[1][0] + MOD ) % MOD ) ;
    for( int i = 2 ; i <= n ; i ++ ) {
        printf(" %lld" , ( dp[i][0] + MOD ) % MOD ) ;
    }

    return 0 ;
}


#include <cstdio>
#include <cstring>

using namespace std ;

const int MAXN = 100000 + 110 ;
const int MAXM = 100 + 10 ;
const int MOD = 1000000007 ;

int data[MAXN] ;
int C[MAXN][MAXM] ;
int dp[MAXN][MAXM] ;

int main() {

    int n , m ; scanf("%d%d" , &n , &m ) ;

    memset( dp , 0 , sizeof( dp ) ) ;
    memset( C , 0 , sizeof( C ) ) ;
    for( int i = 0 ; i < MAXN ; i ++ ) {
        C[i][0] = 1 ;
        for( int j = 1 ; j <= 101 && j <= i ; j ++ ) {
            C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) scanf("%d" , &data[i] ) ;
    for( int i = 0 ; i < m ; i ++ ) {
        int l , r , k ; scanf("%d%d%d" , &l , &r , &k ) ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[l][j] = ( dp[l][j] + C[k][k-j] ) % MOD ;
        for( int j = 0 ; j <= 100 ; j ++ ) dp[r+1][j] = ( dp[r+1][j] - C[k+r-l+1][k-j] ) % MOD ;
    }

    for( int i = 2 ; i <= n ; i ++ ) {
        for( int j = 0 ; j <= 100 ; j ++ ) {
            dp[i][j] = ( ( dp[i][j] + dp[i-1][j] ) % MOD + dp[i-1][j+1] ) % MOD ;
        }
    }

    for( int i = 1 ; i <= n ; i ++ ) dp[i][0] = ( dp[i][0] + data[i] ) % MOD ;

    printf("%d" , ( dp[1][0] + MOD ) % MOD ) ;
    for( int i = 2 ; i <= n ; i ++ ) {
        printf(" %d" , ( dp[i][0] + MOD ) % MOD ) ;
    }

    return 0 ;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#define MAXN 110000
#define MAXK 110
#define MOD 1000000007
using namespace std;

long long a[MAXN] , n , Q , S[MAXN][MAXK] , C[MAXN][MAXK] ;

void inc( long long deep , long long l , long long r , long long k )
{
	if ( k == 0 )
	{
		S[deep][l] ++ ;
		S[deep][r+1] -- ;
		return ;
	}
	S[deep][r+1] = ( S[deep][r+1] - C[r-l+k][k] ) % MOD ;
	inc( deep+1 , l , r , k-1 ) ;
}
int main()
{
	//freopen( "C.in" , "r" , stdin );
	//freopen( "C.out" , "w" , stdout );

	memset( a , 0 , sizeof( a ) );
	memset( S , 0 , sizeof( S ) );

	for ( long long i = 0 ; i < MAXN ; i++ ) C[i][0] = 1 ;
	for ( long long i = 1 ; i < MAXN ; i++ )
		for ( long long j = 1 ; j < min( ( long long )(MAXK) , i+1 ) ; j++ )
			C[i][j] = ( C[i-1][j] + C[i-1][j-1] ) % MOD ;

	scanf( "%I64d%I64d" , &n , &Q );
	for ( long long i = 1 ; i <= n ; i++ ) scanf( "%I64d" , &a[i] );

	while ( Q-- )
	{
		long long l , r , k ;
		scanf( "%I64d%I64d%I64d" , &l , &r , &k );
		inc( 0 , l , r , k );
	}

	for ( long long i = 100 ; i >= 0 ; i-- )
	{
		for ( long long j = 1 ; j <= n ; j++ ) S[i][j] += S[i][j-1] ,S[i][j] %= MOD ;
		for ( long long j = 1 , SUM = 0 ; j <= n ; j++ )
			S[i][j] = ( S[i][j] + SUM + S[i+1][j] ) % MOD , SUM = ( SUM + S[i+1][j] ) % MOD ;
	}
	for ( long long i = 1 ; i <= n ; i++ ) printf( "%I64d " , ( ( a[i] + S[0][i] ) % MOD + MOD ) % MOD );
	printf( "\n" );
	return 0 ;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#define MAXN 110000
#define MAXK 110
#define MOD 1000000007
using namespace std;

long long a[MAXN] , n , Q , S[MAXK][MAXN] , C[MAXN][MAXK] ;

void inc( long long deep , long long l , long long r , long long k )
{
	if ( k == 0 )
	{
		S[deep][l] ++ ;
		S[deep][r+1] -- ;
		return ;
	}
	S[deep][r+1] = ( S[deep][r+1] - C[r-l+k][k] ) % MOD ;
	inc( deep+1 , l , r , k-1 ) ;
}
int main()
{
	//freopen( "C.in" , "r" , stdin );
	//freopen( "C.out" , "w" , stdout );

	memset( a , 0 , sizeof( a ) );
	memset( S , 0 , sizeof( S ) );

	for ( long long i = 0 ; i < MAXN ; i++ ) C[i][0] = 1 ;
	for ( long long i = 1 ; i < MAXN ; i++ )
		for ( long long j = 1 ; j < min( ( long long )(MAXK) , i+1 ) ; j++ )
			C[i][j] = ( C[i-1][j] + C[i-1][j-1] ) % MOD ;

	scanf( "%I64d%I64d" , &n , &Q );
	for ( long long i = 1 ; i <= n ; i++ ) scanf( "%I64d" , &a[i] );

	while ( Q-- )
	{
		long long l , r , k ;
		scanf( "%I64d%I64d%I64d" , &l , &r , &k );
		inc( 0 , l , r , k );
	}

	for ( long long i = 100 ; i >= 0 ; i-- )
	{
		for ( long long j = 1 ; j <= n ; j++ ) S[i][j] += S[i][j-1] ,S[i][j] %= MOD ;
		for ( long long j = 1 , SUM = 0 ; j <= n ; j++ )
			S[i][j] = ( S[i][j] + SUM + S[i+1][j] ) % MOD , SUM = ( SUM + S[i+1][j] ) % MOD ;
	}
	for ( long long i = 1 ; i <= n ; i++ ) printf( "%I64d " , ( ( a[i] + S[0][i] ) % MOD + MOD ) % MOD );
	printf( "\n" );
	return 0 ;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#define MAXN 110000
#define MAXK 110
#define MOD 1000000007
using namespace std;

int a[MAXN] , n , Q , S[MAXN][MAXK] , C[MAXN][MAXK] ;

void inc( int deep , int l , int r , int k )
{
	if ( k == 0 )
	{
		S[deep][l] ++ ;
		S[deep][r+1] -- ;
		return ;
	}
	S[deep][r+1] = ( S[deep][r+1] - C[r-l+k][k] ) % MOD ;
	inc( deep+1 , l , r , k-1 ) ;
}
int main()
{
	//freopen( "C.in" , "r" , stdin );
	//freopen( "C.out" , "w" , stdout );

	memset( a , 0 , sizeof( a ) );
	memset( S , 0 , sizeof( S ) );

	for ( int i = 0 ; i < MAXN ; i++ ) C[i][0] = 1 ;
	for ( int i = 1 ; i < MAXN ; i++ )
		for ( int j = 1 ; j < min( MAXK , i+1 ) ; j++ )
			C[i][j] = ( C[i-1][j] + C[i-1][j-1] ) % MOD ;

	scanf( "%d%d" , &n , &Q );
	for ( int i = 1 ; i <= n ; i++ ) scanf( "%d" , &a[i] );

	while ( Q-- )
	{
		int l , r , k ;
		scanf( "%d%d%d" , &l , &r , &k );
		inc( 0 , l , r , k );
	}

	for ( int i = 100 ; i >= 0 ; i-- )
	{
		for ( int j = 1 ; j <= n ; j++ ) S[i][j] += S[i][j-1] ;
		for ( int j = 1 , SUM = 0 ; j <= n ; j++ )
			S[i][j] = ( S[i][j] + SUM + S[i+1][j] ) % MOD , SUM = ( SUM + S[i+1][j] ) % MOD ;
	}
	for ( int i = 1 ; i <= n ; i++ ) printf( "%d " , ( ( a[i] + S[0][i] ) % MOD + MOD ) % MOD );
	printf( "\n" );
	return 0 ;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#define MAXN 110000
#define MAXK 110
#define MOD 1000000007
using namespace std;

long long a[MAXN] , n , Q , S[MAXN][MAXK] , C[MAXN][MAXK] ;

void inc( long long deep , long long l , long long r , long long k )
{
	if ( k == 0 )
	{
		S[deep][l] ++ ;
		S[deep][r+1] -- ;
		return ;
	}
	S[deep][r+1] = ( S[deep][r+1] - C[r-l+k][k] ) % MOD ;
	inc( deep+1 , l , r , k-1 ) ;
}
int main()
{
	//freopen( "C.in" , "r" , stdin );
	//freopen( "C.out" , "w" , stdout );

	memset( a , 0 , sizeof( a ) );
	memset( S , 0 , sizeof( S ) );

	for ( long long i = 0 ; i < MAXN ; i++ ) C[i][0] = 1 ;
	for ( long long i = 1 ; i < MAXN ; i++ )
		for ( long long j = 1 ; j < min( ( long long )(MAXK) , i+1 ) ; j++ )
			C[i][j] = ( C[i-1][j] + C[i-1][j-1] ) % MOD ;

	scanf( "%I64d%I64d" , &n , &Q );
	for ( long long i = 1 ; i <= n ; i++ ) scanf( "%I64d" , &a[i] );

	while ( Q-- )
	{
		long long l , r , k ;
		scanf( "%I64d%I64d%I64d" , &l , &r , &k );
		inc( 0 , l , r , k );
	}

	for ( long long i = 100 ; i >= 0 ; i-- )
	{
		for ( long long j = 1 ; j <= n ; j++ ) S[i][j] += S[i][j-1] ;
		for ( long long j = 1 , SUM = 0 ; j <= n ; j++ )
			S[i][j] = ( S[i][j] + SUM + S[i+1][j] ) % MOD , SUM = ( SUM + S[i+1][j] ) % MOD ;
	}
	for ( long long i = 1 ; i <= n ; i++ ) printf( "%I64d " , ( ( a[i] + S[0][i] ) % MOD + MOD ) % MOD );
	printf( "\n" );
	return 0 ;
}


#include <iostream>
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cstdio>
#include <assert.h>

#define FOR(i,x,y) for(int i=(x);i<(y);i++)
#define RFOR(i,x,y) for(int i=(x);i>=(y);i--)
#define ABS(x) ((x)>0?(x):-(x))
#define SQ(x) ((x)*(x))
#define mset(x,y) memset(x,y,sizeof(x))
#define INF 1000000000
#define MOD 1000000007
#define pb(X) push_back(X)

using namespace std;

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<double> vd;

lli binom[100010][110];

void init()
{
    for(int i=0;i<=101;i++) binom[i][0]=binom[i][1]=1;

    for(int i=0;i<100010;i++)
    {
        for(int j=1;j<min(101,i);j++) binom[i][j]=(binom[i-1][j]+binom[i-1][j-1])%MOD;
    }
}

lli sum[100010][110];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    init();

    mset(sum,0);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) cin>>sum[i][0];
    int l,r,k;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d\n",&l,&r,&k);
        l--,r--;
        sum[l][k+1]=(sum[l][k+1]+1)%MOD;
        sum[r+1][1]=(sum[r+1][1]-binom[r+1-l+k][k]+1)%MOD;
        sum[r+1][k+1]=(sum[r+1][k+1]-1)%MOD;
    }

    for(int j=101;j>0;j--)
    {
        for(int i=1;i<n;i++) sum[i][j]=(sum[i][j]+sum[i-1][j])%MOD;
        for(int i=0;i<n;i++) sum[i][j-1]=(sum[i][j-1]+sum[i][j])%MOD;
    }

    for(int i=0;i<n;i++)
    {
        if(sum[i][0]<0) sum[i][0]+=MOD;
        cout<<sum[i][0]<<" ";
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cstdio>
#include <assert.h>

#define FOR(i,x,y) for(int i=(x);i<(y);i++)
#define RFOR(i,x,y) for(int i=(x);i>=(y);i--)
#define ABS(x) ((x)>0?(x):-(x))
#define SQ(x) ((x)*(x))
#define mset(x,y) memset(x,y,sizeof(x))
#define INF 1000000000
#define MOD 1000000007
#define pb(X) push_back(X)

using namespace std;

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<double> vd;

lli binom[100010][110];

void init()
{
    for(int i=0;i<=101;i++) binom[i][0]=binom[i][i]=1;

    for(int i=0;i<100010;i++)
    {
        for(int j=1;j<min(101,i);j++) binom[i][j]=(binom[i-1][j]+binom[i-1][j-1])%MOD;
    }
}

lli sum[100010][110];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    init();

    mset(sum,0);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) cin>>sum[i][0];
    int l,r,k;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d",&l,&r,&k);
        l--,r--;
        sum[l][k+1]=(sum[l][k+1]+1)%MOD;
        sum[r+1][1]=(sum[r+1][1]-binom[r+1-l+k][k]+1)%MOD;
        sum[r+1][k+1]=(sum[r+1][k+1]-1)%MOD;
    }

    for(int j=101;j>0;j--)
    {
        for(int i=1;i<n;i++) sum[i][j]=(sum[i][j]+sum[i-1][j])%MOD;
        for(int i=0;i<n;i++) sum[i][j-1]=(sum[i][j-1]+sum[i][j])%MOD;
    }

    for(int i=0;i<n;i++)
    {
        if(sum[i][0]<0) sum[i][0]+=MOD;
        cout<<sum[i][0]<<" ";
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cstdio>
#include <assert.h>

#define FOR(i,x,y) for(int i=(x);i<(y);i++)
#define RFOR(i,x,y) for(int i=(x);i>=(y);i--)
#define ABS(x) ((x)>0?(x):-(x))
#define SQ(x) ((x)*(x))
#define mset(x,y) memset(x,y,sizeof(x))
#define INF 1000000000
#define MOD 1000000007
#define pb(X) push_back(X)

using namespace std;

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<double> vd;

lli binom[101000][110];

void init()
{
    for(int i=0;i<101000;i++)
    {
        binom[i][0]=1;
        if(i<101)binom[i][i]=1;
    }

    for(int i=0;i<101000;i++)
    {
        for(int j=1;j<min(101,i);j++) binom[i][j]=(binom[i-1][j]+binom[i-1][j-1])%MOD;
    }
}

lli sum[101000][110];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    init();

    mset(sum,0);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) cin>>sum[i][0];
    int l,r,k;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d",&l,&r,&k);
        r--,l--;
        for(int j=0;j<=k;j++) sum[l+j][j+1]=(sum[l+j][j+1]+binom[k][k-j])%MOD;
        for(int j=0;j<=k;j++) sum[r+1+j][j+1]=(sum[r+1+j][j+1]-binom[r+1-l+k][k-j])%MOD;
    }

    for(int j=101;j>0;j--)
    {
        for(int i=1;i<n;i++) sum[i][j]=(sum[i][j]+sum[i-1][j])%MOD;
        for(int i=0;i<n;i++) sum[i][j-1]=(sum[i][j-1]+sum[i][j])%MOD;
    }

    for(int i=0;i<n;i++)
    {
        if(sum[i][0]<0) sum[i][0]+=MOD;
        cout<<sum[i][0]<<" ";
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <cstdio>
#include <assert.h>

#define FOR(i,x,y) for(int i=(x);i<(y);i++)
#define RFOR(i,x,y) for(int i=(x);i>=(y);i--)
#define ABS(x) ((x)>0?(x):-(x))
#define SQ(x) ((x)*(x))
#define mset(x,y) memset(x,y,sizeof(x))
#define INF 1000000000
#define MOD 1000000007
#define pb(X) push_back(X)

using namespace std;

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<double> vd;

lli binom[100010][110];

void init()
{
    for(int i=0;i<100010;i++)
    {
        binom[i][0]=1;
        if(i<101)binom[i][i]=1;
    }

    for(int i=0;i<100010;i++)
    {
        for(int j=1;j<min(101,i);j++) binom[i][j]=(binom[i-1][j]+binom[i-1][j-1])%MOD;
    }
}

lli sum[100010][110];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    init();

    mset(sum,0);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) cin>>sum[i][0];
    int l,r,k;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d",&l,&r,&k);
        l--,r--;
        sum[l][k+1]=(sum[l][k+1]+1)%MOD;
        sum[r+1][1]=(sum[r+1][1]-binom[r+1-l+k][k]+1)%MOD;
        sum[r+1][k+1]=(sum[r+1][k+1]-1)%MOD;
    }

    for(int j=101;j>0;j--)
    {
        for(int i=1;i<n;i++) sum[i][j]=(sum[i][j]+sum[i-1][j])%MOD;
        for(int i=0;i<n;i++) sum[i][j-1]=(sum[i][j-1]+sum[i][j])%MOD;
    }

    for(int i=0;i<n;i++)
    {
        if(sum[i][0]<0) sum[i][0]+=MOD;
        cout<<sum[i][0]<<" ";
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
#define rep(i,u,v) for (int i=(u);i<=(v);i++)
#define dto(i,u,v) for (int i=(u);i>=(v);i--)
const long long md=1000000007;
long long c[100005][105],sum[101][100005],a[100005];
int n,m,l,r,k;
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%I64d",&a[i]);
	rep(i,1,100000){
		c[i][0]=1;
		rep(j,1,100)
			c[i][j]=(c[i][j-1]+c[i-1][j])%md;
	}
	while (m--){
		scanf("%d%d%d",&l,&r,&k);
		sum[k][l]=(sum[k][l]+1)%md;
		rep(i,0,k)
			sum[i][r+1]=((sum[i][r+1]-c[r-l+k-i][k-i])%md+md)%md;
	}
	dto(i,k,0){
		rep(j,1,n)
			sum[i][j]=((sum[i][j]+sum[i+1][j]+sum[i][j-1])%md+md)%md;
	}
	rep(i,1,n)
		printf("%I64d ",((sum[0][i]+a[i])%md+md)%md);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
#define rep(i,u,v) for (int i=(u);i<=(v);i++)
#define dto(i,u,v) for (int i=(u);i>=(v);i--)
const long long md=1000000007;
long long c[100005][105],sum[101][100005],a[100005];
int n,m,l,r,k;
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%I64d",&a[i]);
	rep(i,1,100000){
		c[i][0]=1;
		rep(j,1,100)
			c[i][j]=(c[i][j-1]+c[i-1][j])%md;
	}
	while (m--){
		scanf("%d%d%d",&l,&r,&k);
		sum[k][l]=(sum[k][l]+1)%md;
		rep(i,0,k)
			sum[i][r+1]=((sum[i][r+1]-c[r-l+k-i][k-i])%md+md)%md;
	}
	dto(i,k,0){
		rep(j,1,n)
			sum[i][j]=(sum[i][j]+sum[i+1][j]+sum[i][j-1])%md;
	}
	rep(i,1,n)
		printf("%I64d ",(sum[0][i]+a[i])%md);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
#define rep(i,u,v) for (int i=(u);i<=(v);i++)
#define dto(i,u,v) for (int i=(u);i>=(v);i--)
const long long md=1000000007;
long long c[100005][105],sum[101][100005],a[100005];
int n,m,l,r,k;
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%I64d",&a[i]);
	rep(i,1,100000){
		c[i][0]=1;
		rep(j,1,100)
			c[i][j]=(c[i][j-1]+c[i-1][j])%md;
	}
	while (m--){
		scanf("%d%d%d",&l,&r,&k);
		sum[k][l]=(sum[k][l]+1)%md;
		rep(i,0,k)
			sum[i][r+1]=((sum[i][r+1]-c[r-l+k-i][k-i])%md+md)%md;
	}
	dto(i,k,0){
		rep(j,1,n)
			sum[i][j]=((sum[i][j]+sum[i+1][j]+sum[i][j-1])%md+md)&md;
	}
	rep(i,1,n)
		printf("%I64d ",((sum[0][i]+a[i])%md+md)%md);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <vector>
#define inf 0x3fffffff
#define rep(i,s,e) for (int i=(s);i<(e);i++)
/*memset(dp[cur],127,sizeof dp[cur]);*/
using namespace std;

const int mo=1e9+7;

int f[105][110000],c[11000][105];

void inc(int &a,int b)
{
    a=(a+b) % mo;
}

void dec(int &a,int b)
{
    a=(a-b+mo) % mo;
}

int main()
{
    int n,m;
    cin>>n>>m;
    rep(i,1,n+1) cin>>f[0][i];
    rep(i,0,n+100+1) {
        c[i][0]=1;
        rep(j,1,min(i,100)+1) c[i][j]=(c[i-1][j-1]+c[i-1][j]) % mo;
    }
    while( m-- ) {
            int l,r,k;
            cin>>l>>r>>k;
            rep(i,1,k+1) dec(f[i][r+1],c[k-i+1+r-l][k-i+1]);
            inc(f[k+1][l],1); dec(f[k+1][r+1],1);
    }
    for (int i=101; i>0; i--) {
            for (int j=1; j<=n; j++) inc(f[i][j],f[i][j-1]);
            for (int j=1; j<=n; j++) inc(f[i-1][j],f[i][j]);
    }
    rep(i,1,n+1) cout<<f[0][i]<<" ";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <vector>
#define inf 0x3fffffff
#define rep(i,s,e) for (int i=(s);i<(e);i++)
/*memset(dp[cur],127,sizeof dp[cur]);*/
using namespace std;

const int mo=1e9+7;

int f[105][110000],c[110000][105];

void inc(int &a,int b)
{
    a=(a+b) % mo;
}

void dec(int &a,int b)
{
    a=(a-b+mo) % mo;
}

int main()
{
    int n,m;
    cin>>n>>m;
    rep(i,1,n+1) cin>>f[0][i];
    rep(i,0,n+100+1) {
        c[i][0]=1;
        rep(j,1,min(i,100)+1) c[i][j]=(c[i-1][j-1]+c[i-1][j]) % mo;
    }
    while( m-- ) {
            int l,r,k;
            cin>>l>>r>>k;
            rep(i,1,k+1) dec(f[i][r+1],c[k-i+1+r-l][k-i+1]);
            inc(f[k+1][l],1); dec(f[k+1][r+1],1);
    }
    for (int i=101; i>0; i--) {
            for (int j=1; j<=n; j++) inc(f[i][j],f[i][j-1]);
            for (int j=1; j<=n; j++) inc(f[i-1][j],f[i][j]);
    }
    rep(i,1,n+1) cout<<f[0][i]<<" ";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <vector>
#define inf 0x3fffffff
#define rep(i,s,e) for (int i=(s);i<(e);i++)
/*memset(dp[cur],127,sizeof dp[cur]);*/
using namespace std;

const int mo=1e9+7;

int f[105][100050],c[100050][105];

void inc(int &a,int b)
{
    a=(a+b) % mo;
}

void dec(int &a,int b)
{
    a=(a-b+mo) % mo;
}

int main()
{
    int n,m;
    cin>>n>>m;
    rep(i,1,n+1) cin>>f[0][i];
    rep(i,0,n+100+1) {
        c[i][0]=1;
        rep(j,1,min(i,100)+1) c[i][j]=(c[i-1][j-1]+c[i-1][j]) % mo;
    }
    while( m-- ) {
            int l,r,k;
            cin>>l>>r>>k;
            rep(i,1,k+1) dec(f[i][r+1],c[k-i+1+r-l][k-i+1]);
            inc(f[k+1][l],1); dec(f[k+1][r+1],1);
    }
    for (int i=101; i>0; i--) {
            for (int j=1; j<=n; j++) inc(f[i][j],f[i][j-1]);
            for (int j=1; j<=n; j++) inc(f[i-1][j],f[i][j]);
    }
    rep(i,1,n+1) cout<<f[0][i]<<" ";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <vector>
#define inf 0x3fffffff
#define rep(i,s,e) for (int i=(s);i<(e);i++)
/*memset(dp[cur],127,sizeof dp[cur]);*/
using namespace std;

const int mo=1e9+7;

int f[105][100050],c[100050][105];

void inc(int &a,int b)
{
    a=(a+b) % mo;
}

void dec(int &a,int b)
{
    a=(a-b+mo) % mo;
}

int main()
{
    int n,m;
    cin>>n>>m;
    rep(i,1,n+1) cin>>f[0][i];
    rep(i,0,n+100) {
        c[i][0]=1;
        rep(j,1,min(i,100)+1) c[i][j]=(c[i-1][j-1]+c[i-1][j]) % mo;
    }
    while( m-- ) {
            int l,r,k;
            cin>>l>>r>>k;
            rep(i,1,k+1) dec(f[i][r+1],c[k-i+1+r-l][k-i+1]);
            inc(f[k+1][l],1); dec(f[k+1][r+1],1);
    }
    for (int i=101; i>0; i--) {
            for (int j=1; j<=n; j++) inc(f[i][j],f[i][j-1]);
            for (int j=1; j<=n; j++) inc(f[i-1][j],f[i][j]);
    }
    rep(i,1,n+1) cout<<f[0][i]<<" ";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
vector<vector<in> > dfs;
in n;
const in mdl=1000000007LL;
vector<in> fc,invfc;
in ncr(in a, in b){
  if(a<0 || a<b || b<0)
    return 0;
  return (((fc[a]*invfc[b])%mdl)*invfc[a-b])%mdl;
}
void mdf(in lv, in l, in r, in k){
  if(k==0){
    dfs[lv+1][l]++;
    dfs[lv+1][r+1]--;
    return;
  }
  mdf(lv+1,l,r,k-1);
  dfs[lv+1][r+1]-=ncr(r-l+k,k);
}
in pw(in a, in b){
  in r=1;
  for(in i=34;i>=0;i--){
    r*=r;
    r%=mdl;
    if((1LL<<i)&b){
      r*=a;
      r%=mdl;
    }
  }
  return r;
}
in inv(in a){
  return pw(a,mdl-2);
}
const in mk=104;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  in m;
  cin>>n>>m;
  dfs.resize(mk,vector<in>(n+mk,0));
  forn(i,n){
    cin>>dfs[0][i];
  }
  fc.resize(n+mk);
  invfc=fc;
  forn(i,n+mk){
    if(i==0)
      fc[i]=1;
    else
      fc[i]=(i*fc[i-1])%mdl;
    invfc[i]=inv(fc[i]);
  }
  in l,r,k;
  forn(i,m){
    cin>>l>>r>>k;
    l--;r--;
    mdf(0,l,r,k);
  }
  for(in j=mk-2;j>=0;j--){
    in cr=0;
    forv(i,dfs[j]){
      cr+=dfs[j+1][i];
      dfs[j][i]+=cr;
      dfs[j][i]%=mdl;
      cr%=mdl;
    }
  }
  forn(i,n)
    cout<<(dfs[0][i]+mdl)%mdl<<" ";
  cout<<endl;
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
vector<vector<in> > dfs;
in n;
const in mdl=1000000007LL;
vector<in> fc,invfc;
in ncr(in a, in b){
  if(a<0 || a<b || b<0)
    return 0;
  return (((fc[a]*invfc[b])%mdl)*invfc[a-b])%mdl;
}
void mdf(in lv, in l, in r, in k){
  if(k==0){
    dfs[lv+1][l]++;
    dfs[lv+1][r+1]--;
    return;
  }
  mdf(lv+1,l,r,k-1);
  dfs[lv+1][r+1]-=ncr(r-l+k,k);
}
in pw(in a, in b){
  in r=1;
  for(in i=34;i>=0;i--){
    r*=r;
    r%=mdl;
    if((1LL<<i)&b){
      r*=a;
      r%=mdl;
    }
  }
  return r;
}
in inv(in a){
  return pw(a,mdl-2);
}
const in mk=104;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  in m;
  cin>>n>>m;
  dfs.resize(mk,vector<in>(n+mk,0));
  forn(i,n){
    cin>>dfs[0][i];
  }
  fc.resize(n+mk);
  invfc=fc;
  forn(i,n+mk){
    if(i==0)
      fc[i]=1;
    else
      fc[i]=(i*fc[i-1])%mdl;
    invfc[i]=inv(fc[i]);
  }
  in l,r,k;
  forn(i,m){
    cin>>l>>r>>k;
    l--;r--;
    mdf(0,l,r,k);
  }
  for(in j=mk-2;j>=0;j--){
    in cr=0;
    forv(i,dfs[j]){
      cr+=dfs[j+1][i];
      dfs[j][i]+=cr;
    }
  }
  forn(i,n)
    cout<<dfs[0][i]<<" ";
  cout<<endl;
  return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
vector<vector<in> > dfs;
in n;
const in mdl=1000000007LL;
vector<in> fc,invfc;
in ncr(in a, in b){
  if(a<0 || a<b || b<0)
    return 0;
  return (((fc[a]*invfc[b])%mdl)*invfc[a-b])%mdl;
}
void mdf(in lv, in l, in r, in k){
  if(k==0){
    dfs[lv+1][l]++;
    dfs[lv+1][r+1]--;
    return;
  }
  mdf(lv+1,l,r,k-1);
  dfs[lv+1][r+1]-=ncr(r-l+k,k);
}
in pw(in a, in b){
  in r=1;
  for(in i=34;i>=0;i--){
    r*=r;
    r%=mdl;
    if((1LL<<i)&b){
      r*=a;
      r%=mdl;
    }
  }
  return r;
}
in inv(in a){
  return pw(a,mdl-2);
}
const in mk=104;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  in m;
  cin>>n>>m;
  dfs.resize(mk,vector<in>(n+mk,0));
  forn(i,n){
    cin>>dfs[0][i];
  }
  fc.resize(n+mk);
  invfc=fc;
  forn(i,n+mk){
    if(i==0)
      fc[i]=1;
    else
      fc[i]=(i*fc[i-1])%mdl;
    invfc[i]=inv(fc[i]);
  }
  in l,r,k;
  forn(i,m){
    cin>>l>>r>>k;
    l--;r--;
    mdf(0,l,r,k);
  }
  for(in j=mk-2;j>=0;j--){
    in cr=0;
    forv(i,dfs[j]){
      cr+=dfs[j+1][i];
      dfs[j][i]+=cr;
      dfs[j][i]%=mdl;
      cr%=mdl;
    }
  }
  forn(i,n)
    cout<<dfs[0][i]<<" ";
  cout<<endl;
  return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                int val = 1;
                for (int j = K; j >= 0; j --) {
                        (Array[r][j] -= val) %= MOD;
                        val = (lld) val*(r-l+K-j)%MOD*Inv[K-j+1]%MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M],Fun[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
        Fun[0][0] = 1;
        for (int i = 0; i < N; i ++) {
                for (int j = 0; j < M; j ++) {
                        if (i) (Fun[i][j] += Fun[i-1][j]) %= MOD;
                        if (j) (Fun[i][j] += Fun[i][j-1]) %= MOD;
                }
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                for (int j = K; j >= 0; j --) {
                        (Array[r][j] -= Fun[r-l-1][K-j]) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                for (int j = 0; j <= K; j ++) {
                        (Array[r][j] -= C(r-l+K,K-j)-C(r-l+K,K-j-1)) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <stdio.h>
typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],n,m,Array[N][M],Fun[N][M];
inline void add(int &a,int b) {
        a += b;
        if (a>=MOD) a -= MOD;
}
inline void readInt(int &x) {
        char c; bool sig = 0;
        for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c=='-') sig = 1;
        for (x = c-'0'; c = getchar(), c >= '0' && c <= '9'; x = x*10+c-'0');
        sig && (x=-x);
}
int main() {
        Fun[0][0] = 1;
        for (int i = 0; i < N; i ++) {
                for (int j = 0; j < M; j ++) {
                        if (i) add(Fun[i][j],Fun[i-1][j]);
                        if (j) add(Fun[i][j],Fun[i][j-1]);
                }
        }
        readInt(n); readInt(m);
        for (int i = 0; i < n; i ++) readInt(a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                readInt(l); readInt(r); readInt(K); l --;
                add(Array[l][K],1);
                for (int j = K; j >= 0; j --) {
                        add(Array[r][j],MOD-Fun[r-l-1][K-j]);
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) add(Array[i][j],Array[i-1][j]);
                        if (j!=100) add(Array[i][j],Array[i][j+1]);
                }
                printf("%d%c",((a[i]+Array[i][0])%MOD+MOD)%MOD," \n"[i==n-1]);
        }
        return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                for (int j = K; j >= 0; j --) {
                        (Array[r][j] -= C(r-l-1+K,K-j)) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                for (int j = 0; j <= K; j ++) {
                        (Array[r][j] -= C(r-l+K-j-1,K-j)) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                for (int j = K; j >= 0; j --) {
                        (Array[r][j] -= C(r-l+K-1,K-j)) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define P 1000000007
int i, j, f[110],  l, r, k, b[110000][101];
typedef long long lld;

const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;

int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d", &n, &m);
        for (i = 1; i <= n; i++)	scanf("%d", &a[i]);
        while (m--) {
                scanf("%d%d%d", &l, &r, &k);
                for (i = 0; i <= k; i++)	b[l][i] = (b[l][i] + C(k,k - i)) % P;
                for (i = 0; i <= k; i++)	b[r + 1][i] = (b[r + 1][i] - C(r - l + 1 + k,k - i)) % P;
        }
        for (i = 1; i <= n; i++) {
                for (j = 0; j <= 100; j++)	f[j] = (f[j] + b[i][j]) % P;
                a[i] = (a[i] + f[0]) % P;
                for (j = 0; j < 100; j++)	f[j] = (f[j] + f[j + 1]) % P;
        }
        for (i = 1; i <= n; i++)	printf("%d ", (a[i] + P) % P);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                for (int j = 0; j <= K; j ++) {
                        (Array[r][j] -= C(r-l+K,K-j)) %= MOD;
                        if (j!=K) (Array[r][j] += C(r-l+K,K-j-1)) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],n,m,Array[N][M],Fun[N][M];

void init() {
        Fun[0][0] = 1;
        for (int i = 0; i < N; i ++) {
                for (int j = 0; j < M; j ++) {
                        if (i) (Fun[i][j] += Fun[i-1][j]) %= MOD;
                        if (j) (Fun[i][j] += Fun[i][j-1]) %= MOD;
                }
        }
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                for (int j = K; j >= 0; j --) {
                        (Array[r][j] -= Fun[r-l-1][K-j]) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long lld;
const int M = 110;
const int N = 101000+M;
const int MOD = (int)1e9+7;
int a[N],F[N],Finv[N],Inv[N],n,m,Array[N][M];

void init() {
        Inv[1] = 1;
        F[0] = Finv[0] = 1;
        for (int i = 2; i < N; i ++) {
                Inv[i] = (lld)Inv[MOD%i]*(MOD-MOD/i)%MOD;
        }
        for (int i = 1; i < N; i ++) {
                F[i] = (lld)F[i-1]*i%MOD;
                Finv[i] = (lld)Finv[i-1]*Inv[i]%MOD;
        }
}

int C(int a,int b) {
        if (a<b) return 0;
        return (lld)F[a]*Finv[b]%MOD*Finv[a-b]%MOD;
}

int main() {
        init();
        scanf("%d%d",&n,&m);
        for (int i = 0; i < n; i ++) scanf("%d",&a[i]);
        for (int i = 0; i < m; i ++) {
                int l,r,K;
                scanf("%d%d%d",&l,&r,&K); l --;
                (Array[l][K] += 1) %= MOD;
                for (int j = 0; j <= K; j ++) {
                        (Array[r][j] -= C(r-l+K-1,K-j)) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) {
                for (int j = 100; j >= 0; j --) {
                        if (i) (Array[i][j] += Array[i-1][j]) %= MOD;
                        if (j!=100) (Array[i][j] += Array[i][j+1]) %= MOD;
                }
                printf("%d\n",((a[i]+Array[i][0])%MOD+MOD)%MOD);
        }
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef map<string,int> MSI;
typedef long long LL;
template<class T> T sqr(T x) {return x*x;}
template<class T> T f_abs(T x) {return x > 0 ? x : -x;}
#define PI acos(-1)
#define MAXLONGINT 2147483647
#define INT 1e10
#define X first
#define Y second
#define PB push_back
#define MP mack_pair
#define debug(x) cerr<<#x" = "<<(x)<<endl
#define foreach(it,v) for (__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define MAXN 100105
#define M 1000000007

int main()
{
    int n,m; cin>>n>>m;
    int ori[MAXN], a[MAXN][105], c[MAXN][105];
    LL sum[MAXN];
    for(int i = 1; i <= n; i++)
    {
        cin>>ori[i];
        ori[i] %= M;
    }
    c[0][0] = 1;
    for(int i = 1; i <= MAXN-5; i++)
    {
        for(int j = 0; j <= min(100,i); j++)
        {
            if(0 == j) c[i][j] = 1;
            else c[i][j] = c[i-1][j-1] + c[i-1][j];
        }
    }
    memset(sum, 0, sizeof(sum));
    memset(a, 0, sizeof(a));
    int L,r,k,maxk = 0;
    for(int i = 1; i <= m; i++)
    {
        cin>>L>>r>>k;
        maxk = max(maxk, k);
        a[L][k]++;
        for(int j = 0; j <= k; j++)
        {
            a[r+1][j] -= c[r-L+k-j][k-j];
        }
    }
    for(int i = maxk; i >= 0; i--)
    {
        for(int j = 1; j <= n; j++)
        {
            sum[j] = (sum[j] + sum[j-1] + a[j][i]) % M;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        sum[i] = (sum[i] + ori[i]) % M;
    }
    for(int i = 1; i != n; i++)
    {
        cout<<sum[i]<<' ';
    }
    cout<<sum[n]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef map<string,int> MSI;
typedef long long LL;
template<class T> T sqr(T x) {return x*x;}
template<class T> T f_abs(T x) {return x > 0 ? x : -x;}
#define PI acos(-1)
#define MAXLONGINT 2147483647
#define INT 1e10
#define X first
#define Y second
#define PB push_back
#define MP mack_pair
#define debug(x) cerr<<#x" = "<<(x)<<endl
#define foreach(it,v) for (__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define MAXN 100105
#define M 1000000007

int main()
{
    int n,m; cin>>n>>m;
    int ori[MAXN], a[MAXN][105], c[MAXN][105];
    LL sum[MAXN];
    for(int i = 1; i <= n; i++)
    {
        cin>>ori[i];
        ori[i] %= M;
    }
    c[0][0] = 1;
    for(int i = 1; i <= MAXN-5; i++)
    {
        for(int j = 0; j <= min(100,i); j++)
        {
            if(0 == j) c[i][j] = 1;
            else c[i][j] = (c[i-1][j-1] + c[i-1][j]) % M;
        }
    }
    memset(sum, 0, sizeof(sum));
    memset(a, 0, sizeof(a));
    int L,r,k,maxk = 0;
    for(int i = 1; i <= m; i++)
    {
        cin>>L>>r>>k;
        maxk = max(maxk, k);
        a[L][k]++;
        for(int j = 0; j <= k; j++)
        {
            a[r+1][j] -= c[r-L+k-j][k-j];
        }
    }
    for(int i = maxk; i >= 0; i--)
    {
        for(int j = 1; j <= n; j++)
        {
            sum[j] = (sum[j] + sum[j-1] + a[j][i] + M) % M;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        sum[i] = (sum[i] + ori[i] + M) % M;
    }
    for(int i = 1; i != n; i++)
    {
        cout<<sum[i]<<' ';
    }
    cout<<sum[n]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef map<string,int> MSI;
typedef long long LL;
template<class T> T sqr(T x) {return x*x;}
template<class T> T f_abs(T x) {return x > 0 ? x : -x;}
#define PI acos(-1)
#define MAXLONGINT 2147483647
#define INT 1e10
#define X first
#define Y second
#define PB push_back
#define MP mack_pair
#define debug(x) cerr<<#x" = "<<(x)<<endl
#define foreach(it,v) for (__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define MAXN 100105
#define M 1000000007

int main()
{
    int n,m; cin>>n>>m;
    int ori[MAXN], a[MAXN][105], c[MAXN][105];
    LL sum[MAXN];
    for(int i = 1; i <= n; i++)
    {
        cin>>ori[i];
    }
    c[0][0] = 1;
    for(int i = 1; i <= MAXN-5; i++)
    {
        for(int j = 0; j <= min(100,i); j++)
        {
            if(0 == j) c[i][j] = 1;
            else c[i][j] = c[i-1][j-1] + c[i-1][j];
        }
    }
    memset(sum, 0, sizeof(sum));
    memset(a, 0, sizeof(a));
    int L,r,k,maxk = 0;
    for(int i = 1; i <= m; i++)
    {
        cin>>L>>r>>k;
        maxk = max(maxk, k);
        a[L][k]++;
        for(int j = 0; j <= k; j++)
        {
            a[r+1][j] -= c[r-L+k-j][k-j];
        }
    }
    for(int i = maxk; i >= 0; i--)
    {
        for(int j = 1; j <= n; j++)
        {
            sum[j] = (sum[j] + sum[j-1] + a[j][i]) % M;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        sum[i] = (sum[i] + ori[i]) % M;
    }
    for(int i = 1; i != n; i++)
    {
        cout<<sum[i]<<' ';
    }
    cout<<sum[n]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef map<string,int> MSI;
typedef long long LL;
template<class T> T sqr(T x) {return x*x;}
template<class T> T f_abs(T x) {return x > 0 ? x : -x;}
#define PI acos(-1)
#define MAXLONGINT 2147483647
#define INT 1e10
#define X first
#define Y second
#define PB push_back
#define MP mack_pair
#define debug(x) cerr<<#x" = "<<(x)<<endl
#define foreach(it,v) for (__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define MAXN 100105
#define M 1000000007

int main()
{
    int n,m; cin>>n>>m;
    int ori[MAXN], a[MAXN][105], c[MAXN][105];
    LL sum[MAXN];
    for(int i = 1; i <= n; i++)
    {
        cin>>ori[i];
        ori[i] %= M;
    }
    c[0][0] = 1;
    for(int i = 1; i <= MAXN-5; i++)
    {
        for(int j = 0; j <= min(100,i); j++)
        {
            if(0 == j) c[i][j] = 1;
            else c[i][j] = (c[i-1][j-1] + c[i-1][j]) % M;
        }
    }
    memset(sum, 0, sizeof(sum));
    memset(a, 0, sizeof(a));
    int L,r,k,maxk = 0;
    for(int i = 1; i <= m; i++)
    {
        cin>>L>>r>>k;
        maxk = max(maxk, k);
        a[L][k]++;
        for(int j = 0; j <= k; j++)
        {
            a[r+1][j] = (a[r+1][j] - c[r-L+k-j][k-j]) % M;
        }
    }
    for(int i = maxk; i >= 0; i--)
    {
        for(int j = 1; j <= n; j++)
        {
            sum[j] = (sum[j] + sum[j-1] + a[j][i]) % M;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        sum[i] = (sum[i] + ori[i] + M) % M;
    }
    for(int i = 1; i != n; i++)
    {
        cout<<sum[i]<<' ';
    }
    cout<<sum[n]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef map<string,int> MSI;
typedef long long LL;
template<class T> T sqr(T x) {return x*x;}
template<class T> T f_abs(T x) {return x > 0 ? x : -x;}
#define PI acos(-1)
#define MAXLONGINT 2147483647
#define INT 1e10
#define X first
#define Y second
#define PB push_back
#define MP mack_pair
#define debug(x) cerr<<#x" = "<<(x)<<endl
#define foreach(it,v) for (__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define MAXN 100105
#define M 1000000007

int main()
{
    int n,m; cin>>n>>m;
    int ori[MAXN], a[MAXN][105], c[MAXN][105], sum[MAXN];
    for(int i = 1; i <= n; i++)
    {
        cin>>ori[i];
    }
    c[0][0] = 1;
    for(int i = 1; i <= MAXN-5; i++)
    {
        for(int j = 0; j <= min(100,i); j++)
        {
            if(0 == j) c[i][j] = 1;
            else c[i][j] = c[i-1][j-1] + c[i-1][j];
        }
    }
    memset(sum, 0, sizeof(sum));
    memset(a, 0, sizeof(a));
    int L,r,k,maxk = 0;
    for(int i = 1; i <= m; i++)
    {
        cin>>L>>r>>k;
        maxk = max(maxk, k);
        a[L][k]++;
        for(int j = 0; j <= k; j++)
        {
            a[r+1][j] -= c[r-L+k-j][k-j];
        }
    }
    for(int i = maxk; i >= 0; i--)
    {
        for(int j = 1; j <= n; j++)
        {
            sum[j] = (sum[j] + sum[j-1] + a[j][i]) % M;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        sum[i] = (sum[i] + ori[i]) % M;
    }
    for(int i = 1; i != n; i++)
    {
        cout<<sum[i]<<' ';
    }
    cout<<sum[n]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef map<string,int> MSI;
typedef long long LL;
template<class T> T sqr(T x) {return x*x;}
template<class T> T f_abs(T x) {return x > 0 ? x : -x;}
#define PI acos(-1)
#define MAXLONGINT 2147483647
#define INT 1e10
#define X first
#define Y second
#define PB push_back
#define MP mack_pair
#define debug(x) cerr<<#x" = "<<(x)<<endl
#define foreach(it,v) for (__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define MAXN 100105
#define M 1000000007

int main()
{
    int n,m; cin>>n>>m;
    int ori[MAXN], a[MAXN][105], c[MAXN][105];
    LL sum[MAXN];
    for(int i = 1; i <= n; i++)
    {
        cin>>ori[i];
        ori[i] %= M;
    }
    c[0][0] = 1;
    for(int i = 1; i <= MAXN-5; i++)
    {
        for(int j = 0; j <= min(100,i); j++)
        {
            if(0 == j) c[i][j] = 1;
            else c[i][j] = c[i-1][j-1] + c[i-1][j];
        }
    }
    memset(sum, 0, sizeof(sum));
    memset(a, 0, sizeof(a));
    int L,r,k,maxk = 0;
    for(int i = 1; i <= m; i++)
    {
        cin>>L>>r>>k;
        maxk = max(maxk, k);
        a[L][k]++;
        for(int j = 0; j <= k; j++)
        {
            a[r+1][j] -= c[r-L+k-j][k-j];
        }
    }
    for(int i = maxk; i >= 0; i--)
    {
        for(int j = 1; j <= n; j++)
        {
            sum[j] = (sum[j] + sum[j-1] + a[j][i] + M) % M;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        sum[i] = (sum[i] + ori[i] + M) % M;
    }
    for(int i = 1; i != n; i++)
    {
        cout<<sum[i]<<' ';
    }
    cout<<sum[n]<<endl;
    return 0;
}


from sys import stdin
a = []
ans = 0
def insert(id):
    global ans

    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans[0] += a[id]

    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans[0] -= a[id]

def erase(id):
    global ans

    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans[0] -= a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans[0] += a[id]

for _ in range(int(input())):
    ans = [0]
    n, q = map(int, stdin.readline().split())

    a = list(map(int, stdin.readline().split()))
    a.insert(0, -1)
    a.append(-1)

    for i in range(1, n + 1):
        insert(i)

    print(ans[0])
    for i in range(q):
        l, r = map(int, stdin.readline().split())
        if l == r:
            print(ans[0])
            continue
        erase(l - 1)
        erase(l)
        erase(l + 1)
        if l + 1 < r + 1:
            erase(r + 1)
        if l + 1 < r:
            erase(r)
        if l + 1 < r - 1:
            erase(r - 1)
        x = a[l]
        a[l] = a[r]
        a[r] = x
        # swap(a[l], a[r])
        insert(l - 1)
        insert(l)
        insert(l + 1)
        if l + 1 < r + 1:
            insert(r + 1)
        if l + 1 < r:
            insert(r)
        if l + 1 < r - 1:
            insert(r - 1)
        print(ans[0])


# from sys import stdin, stdout
# input = stdin.readline
#
# a = []
# ans = 0
# n = 0
# def up(id):
#     global ans
#     global n
#     if id < 1 or id > n:
#         return
#     if a[id-1] < a[id] and a[id+1] < a[id]:
#         ans += a[id]
#     if a[id-1] > a[id] and a[id+1] > a[id]:
#         ans -= a[id]
#
# def erase(id):
#     global ans
#     global n
#     if id < 1 or id > n:
#         return
#     if a[id-1] < a[id] and a[id+1] < a[id]:
#         ans -= a[id]
#     if a[id-1] > a[id] and a[id+1] > a[id]:
#         ans += a[id]
#
#
#
#
# for _ in range(int(input())):
#
#     ans = 0
#
#     n, q = map(int, input().split())
#
#     *a, = map(int, input().split())
#     a = [0] + a + [0]
#     for i in range(1, n + 1):
#         up(i)
#
#     print(ans)
#     for i in range(q):
#         l, r = map(int, input().split())
#         if l == r:
#             print(ans)
#             continue
#
#         erase(l - 1)
#         erase(l)
#         erase(l + 1)
#         if l + 1 < r + 1:
#             erase(r + 1)
#         if l + 1 < r:
#             erase(r)
#         if l + 1 < r - 1:
#             erase(r - 1)
#
#         a[l], a[r] = a[r], a[l]
#
#         up(l - 1)
#         up(l)
#         up(l + 1)
#         if l + 1 < r + 1:
#             up(r + 1)
#         if l + 1 < r:
#             up(r)
#         if l + 1 < r - 1:
#             up(r - 1)
#         print(ans)

from sys import stdin, stdout

input = stdin.readline

ans = 0
a = []
b = []

def up(id):
    global ans
    global n
    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans += a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans -= a[id]

def erase(id):
    global ans
    global n
    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans -= a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans += a[id]

# print(a[i], a[i - 1] < i)
for _ in range(int(input())):
    ans = 0
    n, q = map(int, input().split())
    *a, = map(int, input().split())
    a = [0] + a + [0]
    b = [0] * (n + 2)
    for i in range(1, n + 1):
        up(i)
    print(ans)
    for i in range(q):
        l, r = map(int, input().split())
        erase(l)
        erase(l - 1)
        erase(l + 1)
        if l+1<r:
            erase(r)
        if l + 1 < r-1:
            erase(r - 1)
        erase(r + 1)
        a[l], a[r] = a[r], a[l]
        up(l)
        up(l - 1)
        up(l + 1)
        if l + 1 < r:
            up(r)
        if l + 1 < r-1:
            up(r - 1)
        up(r + 1)
        print(ans)


from sys import stdin
a = []
ans = 0
n = 0
def up(id):
    global ans
    global n
    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans += a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans -= a[id]

def erase(id):
    global ans
    global n
    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans -= a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans += a[id]

for _ in range(int(input())):

    ans = 0
    n, q = map(int, stdin.readline().split())

    a = list(map(int, stdin.readline().split()))
    a = [-1] + a + [-1]
    for i in range(1, n + 1):
        up(i)

    print(ans)
    for i in range(q):
        l, r = map(int, stdin.readline().split())
        if l > r:
            t = l
            l = r
            r = t
        if l == r:
            print(ans)
            continue
        erase(l - 1)
        erase(l)
        erase(l + 1)
        if l + 1 < r + 1:
            erase(r + 1)
        if l + 1 < r:
            erase(r)
        if l + 1 < r - 1:
            erase(r - 1)

        x = a[l]
        a[l] = a[r]
        a[r] = x

        up(l - 1)
        up(l)
        up(l + 1)
        if l + 1 < r + 1:
            up(r + 1)
        if l + 1 < r:
            up(r)
        if l + 1 < r - 1:
            up(r - 1)
        print(ans)


from sys import stdin, stdout
import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

a = []
ans = 0
n = 0
def relax(id):
    global ans
    if a[id] == 0:
        return

    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans += a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans -= a[id]

def relax1(id):
    global ans
    if a[id] == 0:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans -= a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans += a[id]

t = int(input())
for _ in range(t):

    ans = 0

    n, q = map(int, input().split())

    *a, = map(int, input().split())
    a = [0] + a + [0]
    for i in range(1, n + 1):
        relax(i)

    print(ans)
    for i in range(q):
        l, r = map(int, input().split())
        if l == r:
            print(ans)
            continue

        relax1(l - 1)
        relax1(l)
        relax1(l + 1)

        relax1(r + 1)
        if l + 1 < r:
            relax1(r)
        if l + 1 < r - 1:
            relax1(r - 1)

        a[l], a[r] = a[r], a[l]

        relax(l - 1)
        relax(l)
        relax(l + 1)

        relax(r + 1)
        if l + 1 < r:
            relax(r)
        if l + 1 < r - 1:
            relax(r - 1)
        print(ans)


from sys import stdin, stdout
input = stdin.readline

a = []
ans = 0
n = 0
def relax(id):
    global ans
    if a[id] == 0:
        return

    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans += a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans -= a[id]

def relax1(id):
    global ans
    if a[id] == 0:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans -= a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans += a[id]

for _ in range(int(input())):

    ans = 0

    n, q = map(int, input().split())

    *a, = map(int, input().split())
    a = [0] + a + [0]
    for i in range(1, n + 1):
        relax(i)

    print(ans)
    for i in range(q):
        l, r = map(int, input().split())
        if l == r:
            print(ans)
            continue

        relax1(l - 1)
        relax1(l)
        relax1(l + 1)

        relax1(r + 1)
        if l + 1 < r:
            relax1(r)
        if l + 1 < r - 1:
            relax1(r - 1)

        a[l], a[r] = a[r], a[l]

        relax(l - 1)
        relax(l)
        relax(l + 1)

        relax(r + 1)
        if l + 1 < r:
            relax(r)
        if l + 1 < r - 1:
            relax(r - 1)
        print(ans)


from sys import stdin
input = stdin.readline

a = []
ans = 0
n = 0
def up(id):
    global ans
    if a[id] == 0:
        return

    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans += a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans -= a[id]

def erase(id):
    global ans
    if a[id] == 0:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans -= a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans += a[id]

for _ in range(int(input())):

    ans = 0

    n, q = map(int, input().split())
    a = [0]*(n+2)
    *a, = map(int, input().split())
    a = [0] + a + [0]
    for i in range(1, n + 1):
        up(i)

    print(ans)
    for i in range(q):
        l, r = map(int, input().split())
        if l == r:
            print(ans)
            continue

        erase(l - 1)
        erase(l)
        erase(l + 1)
        erase(r + 1)
        if l + 1 < r:
            erase(r)
        if l + 1 < r - 1:
            erase(r - 1)

        a[l], a[r] = a[r], a[l]

        up(l - 1)
        up(l)
        up(l + 1)

        up(r + 1)
        if l + 1 < r:
            up(r)
        if l + 1 < r - 1:
            up(r - 1)
        print(ans)


from sys import stdin, stdout
input = stdin.readline

c = 0
a = []
b = []

def f(i):
	if a[i] == 0:
		return 0
	if a[i - 1] < a[i] > a[i + 1]:
		return 1
	if a[i - 1] > a[i] < a[i + 1]:
		return -1
	return 0

def relax(i):
	global c
	c += (f(i) - b[i]) * a[i]
	b[i] = f(i)

def relax1(i):
	global c
	c -= b[i] * a[i]
	b[i] = 0
	#print(a[i], a[i - 1] < i)
for _ in range(int(input())):
	c = 0
	n, q = map(int, input().split())
	*a, = map(int, input().split())
	a = [0] + a + [0]
	b = [0] * (n + 2)
	for i in range(1, n + 1):
		relax(i)
	print(c)
	for i in range(q):
		l, r = map(int, input().split())
		relax1(l)
		relax1(l - 1)
		relax1(l + 1)
		relax1(r)
		relax1(r - 1)
		relax1(r + 1)
		a[l], a[r] = a[r], a[l]
		relax(l)
		relax(l - 1)
		relax(l + 1)
		relax(r)
		relax(r - 1)
		relax(r + 1)
		print(c)


from sys import stdin

def insert(a, id, ans):

    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans[0] += a[id]
        # print("id:"+ str(id) +" "+str(a[id]))

    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans[0] -= a[id]

def erase(a, id, ans):
    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans[0] -= a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans[0] += a[id]

for _ in range(int(input())):
    ans = [0]
    n, q = map(int, stdin.readline().split())

    a = list(map(int, stdin.readline().split()))
    a.insert(0, -1)
    a.append(-1)
    # print(a)

    for i in range(1, n + 1):
        insert(a, i, ans)

    print(ans[0])
    for i in range(q):
        l, r = map(int, stdin.readline().split())
        if l == r:
            print(ans[0])
            continue
        erase(a, l - 1, ans)
        erase(a, l, ans)
        erase(a, l + 1, ans)
        if l + 1 < r + 1:
            erase(a, r + 1, ans)
        if l + 1 < r:
            erase(a, r, ans)
        if l + 1 < r - 1:
            erase(a, r - 1, ans)
        x = a[l]
        a[l] = a[r]
        a[r] = x
        # swap(a[l], a[r])
        insert(a, l - 1, ans)
        insert(a, l, ans)
        insert(a, l + 1, ans)
        if l + 1 < r + 1:
            insert(a, r + 1, ans)
        if l + 1 < r:
            insert(a, r, ans)
        if l + 1 < r - 1:
            insert(a, r - 1, ans)
        print(ans[0])


from sys import stdin
a = []
ans = 0
def up(id):
    global ans

    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans += a[id]

    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans -= a[id]

def erase(id):
    global ans

    if id < 1 or id > n:
        return
    if a[id-1] < a[id] and a[id+1] < a[id]:
        ans -= a[id]
    if a[id-1] > a[id] and a[id+1] > a[id]:
        ans += a[id]

for _ in range(int(input())):
    ans = 0
    n, q = map(int, stdin.readline().split())

    a = list(map(int, stdin.readline().split()))
    a = [-1] + a + [-1]

    for i in range(1, n + 1):
        up(i)

    print(ans)
    for i in range(q):
        l, r = map(int, stdin.readline().split())
        if l == r:
            print(ans)
            continue
        erase(l - 1)
        erase(l)
        erase(l + 1)
        if l + 1 < r + 1:
            erase(r + 1)
        if l + 1 < r:
            erase(r)
        if l + 1 < r - 1:
            erase(r - 1)
        x = a[l]
        a[l] = a[r]
        a[r] = x
        # swap(a[l], a[r])
        up(l - 1)
        up(l)
        up(l + 1)
        if l + 1 < r + 1:
            up(r + 1)
        if l + 1 < r:
            up(r)
        if l + 1 < r - 1:
            up(r - 1)
        print(ans)


import sys
read = lambda: sys.stdin.readline().strip()
readi = lambda: map(int, read().split())
from collections import *
from math import *

for _ in range(int(read())):
    n, q = readi()
    nums = [0] + list(readi()) + [0]

    diff = [0] * (n+1)
    for i in range(1, n+1):
        diff[i] = max(0, nums[i] - nums[i+1])
    ans = sum(diff)
    print(ans)
    for _ in range(q):
        a, b = readi()
        av, bv = nums[a], nums[b]

        nums[a] = bv
        ans -= diff[a-1] + diff[a]
        diff[a-1] = max(0, nums[a-1] - nums[a])
        diff[a] = max(0, nums[a] - nums[a+1])
        ans += diff[a-1] + diff[a]

        nums[b] = av
        ans -= diff[b-1] + diff[b]
        diff[b-1] = max(0, nums[b-1] - nums[b])
        diff[b] = max(0, nums[b] - nums[b+1])
        ans += diff[b-1] + diff[b]

        print(ans)


import sys
read = lambda: sys.stdin.readline().strip()
readi = lambda: map(int, read().split())
from collections import *
from math import *

def findMaximas(i):

    temp = maximas[i]
    if nums[i-1] < nums[i] and nums[i] > nums[i+1]:
        maximas[i] = 1
    elif nums[i-1] >nums[i] and nums[i] < nums[i+1]:
        maximas[i] = -1
    else:
        maximas[i] = 0

    return maximas[i]

for _ in range(int(read())):
    n, q = readi()
    nums = list(readi())

    nums.insert(0, 0)
    nums.append(0)
    maximas = [0] * (n+2)
    for i in range(1, n+1):
        findMaximas(i)
    ans = sum([ nums[i]*maximas[i] for i in range(n+2)])
    # print(nums)
    # print(maximas)
    print(ans)
    for _ in range(q):
        a, b = readi()
        tempS = set([a-1, a, a+1, b-1, b, b+1])
        for i in tempS: ans -= nums[i] * maximas[i]
        nums[a], nums[b] = nums[b], nums[a]
        s = set()
        ans += nums[a-1] * findMaximas(a-1) if 0 < a-1 < n+1 and a-1 not in s else 0
        s.add(a-1)
        ans += nums[a] * findMaximas(a) if 0 < a < n+1 and a not in s else 0
        s.add(a)
        ans += nums[a+1] * findMaximas(a+1) if 0 < a+1 < n+1 and a+1 not in s else 0
        s.add(a+1)
        ans += nums[b-1] * findMaximas(b-1) if 0 < b-1 < n+1 and b-1 not in s else 0
        s.add(b-1)
        ans += nums[b] * findMaximas(b) if 0 < b < n+1 and b not in s else 0
        s.add(b)
        ans += nums[b+1] * findMaximas(b+1) if 0 < b+1 < n+1 and b+1 not in s else 0
        s.add(b+1)
        # print(nums)
        # print(maximas)
        print(ans)


# import sys
import os,io
read = lambda: io.BytesIO(os.read(0, os.fstat(0).st_size)).readline()
readi = lambda: map(int, read().split())
from collections import *
from math import *

def findMaximas(i):

    temp = maximas[i]
    if nums[i-1] < nums[i] and nums[i] > nums[i+1]:
        maximas[i] = 1
    elif nums[i-1] >nums[i] and nums[i] < nums[i+1]:
        maximas[i] = -1
    else:
        maximas[i] = 0

    return maximas[i]

for _ in range(int(read())):
    n, q = readi()
    nums = list(readi())

    nums.insert(0, 0)
    nums.append(0)
    maximas = [0] * (n+2)
    for i in range(1, n+1):
        findMaximas(i)
    ans = sum([ nums[i]*maximas[i] for i in range(n+2)])
    # print(nums)
    # print(maximas)
    print(ans)
    for _ in range(q):
        a, b = readi()
        tempS = set([a-1, a, a+1, b-1, b, b+1])
        for i in tempS: ans -= nums[i] * maximas[i]
        nums[a], nums[b] = nums[b], nums[a]
        s = set()
        ans += nums[a-1] * findMaximas(a-1) if 0 < a-1 < n+1 and a-1 not in s else 0
        s.add(a-1)
        ans += nums[a] * findMaximas(a) if 0 < a < n+1 and a not in s else 0
        s.add(a)
        ans += nums[a+1] * findMaximas(a+1) if 0 < a+1 < n+1 and a+1 not in s else 0
        s.add(a+1)
        ans += nums[b-1] * findMaximas(b-1) if 0 < b-1 < n+1 and b-1 not in s else 0
        s.add(b-1)
        ans += nums[b] * findMaximas(b) if 0 < b < n+1 and b not in s else 0
        s.add(b)
        ans += nums[b+1] * findMaximas(b+1) if 0 < b+1 < n+1 and b+1 not in s else 0
        s.add(b+1)
        # print(nums)
        # print(maximas)
        print(ans)


import sys
read = lambda: sys.stdin.readline().strip()
readi = lambda: map(int, read().split())
from collections import *
from math import *

for _ in range(int(read())):
    n, q = readi()
    nums = list(readi())

    ans = 0
    temp = [nums[0]]
    for i in range(1, n):

        if temp[-1] < nums[i]:
            # print(temp)
            if len(temp) > 1:
                ans += temp[0] - temp[-1]
            temp = list()
        temp.append(nums[i])

    # print(temp)
    print(ans + temp[0])

    for _ in range(q):
        a, b = readi()
        nums[a-1], nums[b-1] = nums[b-1], nums[a-1]
        ans = 0
        temp = [nums[0]]
        for i in range(1, n):

            if temp[-1] < nums[i]:
                # print(temp)
                if len(temp) > 1:
                    ans += temp[0] - temp[-1]
                temp = list()
            temp.append(nums[i])

        # print(temp)
        print(ans + temp[0])


import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]

def solve():
    n, q = idata()
    data = [-1] + idata() + [-1]
    ans = 0
    min_max = [0] * (n + 2)
    for i in range(1, n + 1):
        if data[i - 1] < data[i] > data[i + 1]:
            ans += data[i]
            min_max[i] = 1
        if data[i - 1] > data[i] < data[i + 1]:
            ans -= data[i]
            min_max[i] = -1
    print(ans)
    for i in range(q):
        l, r = idata()
        sp = [l - 1, l, l + 1, r - 1, r, r + 1]
        sp = sorted(list(set(sp)))
        for j in range(len(sp)):
            ans -= min_max[sp[j]] * data[sp[j]]
        data[r], data[l] = data[l], data[r]
        for j in range(len(sp)):
            if 0 < sp[j] < n + 1:
                if data[sp[j] - 1] < data[sp[j]] > data[sp[j] + 1]:
                    min_max[sp[j]] = 1
                elif data[sp[j] - 1] > data[sp[j]] < data[sp[j] + 1]:
                    min_max[sp[j]] = -1
                else:
                    min_max[sp[j]] = 0
                ans += min_max[sp[j]] * data[sp[j]]
        print(ans)
    return

for t in range(int(ii())):
    solve()


import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]

def solve():
    n, q = idata()
    data = [-1] + idata() + [-1]
    ans = 0
    ma = [0] * (n + 2)
    for i in range(1, n + 1):
        if data[i - 1] < data[i] > data[i + 1]:
            ans += data[i]
            ma[i] = 1
        if data[i - 1] > data[i] < data[i + 1]:
            ans -= data[i]
            ma[i] = -1
    print(ans)
    for i in range(q):
        l, r = idata()
        l, r = [l - 1, l, l + 1], [r - 1, r, r + 1]
        for j in range(3):
            ans -= ma[l[j]] * data[l[j]]
            if r[j] not in l:
                ans -= ma[r[j]] * data[r[j]]
        data[r[1]], data[l[1]] = data[l[1]], data[r[1]]
        for j in range(3):
            if 0 < l[j] < n + 1:
                if data[l[j] - 1] < data[l[j]] > data[l[j] + 1]:
                    ans += data[l[j]]
                    ma[l[j]] = 1
                elif data[l[j] - 1] > data[l[j]] < data[l[j] + 1]:
                    ans -= data[l[j]]
                    ma[l[j]] = -1
                else:
                    ma[l[j]] = 0
            if r[j] not in l:
                if 0 < r[j] < n + 1:
                    if data[r[j] - 1] < data[r[j]] > data[r[j] + 1]:
                        ans += data[r[j]]
                        ma[r[j]] = 1
                    elif data[r[j] - 1] > data[r[j]] < data[r[j] + 1]:
                        ans -= data[r[j]]
                        ma[r[j]] = -1
                    else:
                        ma[r[j]] = 0
        print(ans)
    return

for t in range(int(ii())):
    solve()


import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline()

# ------------------------------

def RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def print_list(l):
    print(' '.join(map(str,l)))
# sys.setrecursionlimit(300000)
# from heapq import *
# from collections import deque as dq
# from math import ceil,floor,sqrt,pow
# import bisect as bs
# from collections import Counter
# from collections import defaultdict as dc
data = [list(map(int,line.split())) for line in sys.stdin.readlines()]
line = 1
for _ in range(data[0][0]):
    n,q = data[line]
    a = [0]+data[line+1]+[0]
    low,high = set(),set()
    s = 0
    for i in range(1,n+1):
        if a[i]>a[i-1] and a[i]>a[i+1]:
            high.add(a[i])
            s+=a[i]
        elif a[i]<a[i-1] and a[i]<a[i+1]:
            low.add(a[i])
            s-=a[i]
    print(s)
    for ii in range(line+2,line+q+2):
        x,y = data[ii]
        a[x],a[y] = a[y],a[x]
        d = {a[x-1],a[x],a[x+1],a[y-1],a[y],a[y+1]}
        t = low & d
        s+=sum(t)
        low-=t
        t = high & d
        s-=sum(t)
        high-=t
        d = {x-1,x,x+1,y-1,y,y+1}
        for i in d:
            if 0<i<=n:
                if a[i]>a[i-1] and a[i]>a[i+1]:
                    high.add(a[i])
                    s+=a[i]
                elif a[i]<a[i-1] and a[i]<a[i+1]:
                    low.add(a[i])
                    s-=a[i]
        print(s)
    line+=q+2


import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline()

# ------------------------------

def RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def print_list(l):
    print(' '.join(map(str,l)))
# sys.setrecursionlimit(300000)
# from heapq import *
# from collections import deque as dq
# from math import ceil,floor,sqrt,pow
# import bisect as bs
# from collections import Counter
# from collections import defaultdict as dc
data = [list(map(int,line.split())) for line in sys.stdin.readlines()]
line = 1
for _ in range(data[0][0]):
    n,q = data[line]
    a = [0]+data[line+1]+[0]
    low,high = set(),set()
    s = 0
    for i in range(1,n+1):
        if a[i]>a[i-1] and a[i]>a[i+1]:
            high.add(a[i])
            s+=a[i]
        elif a[i]<a[i-1] and a[i]<a[i+1]:
            low.add(a[i])
            s-=a[i]
    print(s)
    for _ in range(q):
        x,y = RL()
        a[x],a[y] = a[y],a[x]
        d = {a[x-1],a[x],a[x+1],a[y-1],a[y],a[y+1]}
        t = low & d
        s+=sum(t)
        low-=t
        t = high & d
        s-=sum(t)
        high-=t
        d = {x-1,x,x+1,y-1,y,y+1}
        for i in d:
            if 0<i<=n:
                if a[i]>a[i-1] and a[i]>a[i+1]:
                    high.add(a[i])
                    s+=a[i]
                elif a[i]<a[i-1] and a[i]<a[i+1]:
                    low.add(a[i])
                    s-=a[i]
        print(s)
    line+=q+2


import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline()

# ------------------------------

def RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def print_list(l):
    print(' '.join(map(str,l)))
# sys.setrecursionlimit(300000)
# from heapq import *
# from collections import deque as dq
# from math import ceil,floor,sqrt,pow
# import bisect as bs
# from collections import Counter
# from collections import defaultdict as dc

for _ in range(N()):
    n,q = RL()
    a = [0]+RLL()+[0]
    low,high = set(),set()
    s = 0
    for i in range(1,n+1):
        if a[i]>a[i-1] and a[i]>a[i+1]:
            high.add(a[i])
            s+=a[i]
        elif a[i]<a[i-1] and a[i]<a[i+1]:
            low.add(a[i])
            s-=a[i]
    print(s)
    for _ in range(q):
        x,y = RL()
        a[x],a[y] = a[y],a[x]
        t = low & {a[x-1],a[x],a[x+1],a[y-1],a[y],a[y+1]}
        s+=sum(t)
        low-=t
        t = high & {a[x-1],a[x],a[x+1],a[y-1],a[y],a[y+1]}
        s-=sum(t)
        high-=t
        d = {x-1,x,x+1,y-1,y,y+1}
        for i in d:
            if 0<i<=n:
                if a[i]>a[i-1] and a[i]>a[i+1]:
                    high.add(a[i])
                    s+=a[i]
                elif a[i]<a[i-1] and a[i]<a[i+1]:
                    low.add(a[i])
                    s-=a[i]
        print(s)


from math import inf as _inf
import sys as _sys
# ans = []

def input():
    result = _sys.stdin.readline()
    assert result[-1] == "\n"
    return result[:-1]

def change(i,i1):
    totChange = 0
    for i in range(i-1, i1+2):
        if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
            totChange+=arr[i]
        elif arr[i] > arr[i-1] and arr[i] > arr[i+1]:
            totChange -= arr[i]
    return totChange
arr = []
for _ in range(int(input())):
    n,q = list(map(int,input().split(" ")))
    arr = [-99,-98] + list(map(int,input().split())) + [-98,-99]
    flag = False
    s = 0
    for i in range(2,n+2):
        if not flag:
            if arr[i] > arr[i-1] and arr[i] > arr[i+1]:
                s+=arr[i]
                flag = not flag
        else:
            if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
                s-=arr[i]
                flag = not flag
    _sys.stdout.write(str(s) + "\n")
    for i in range(q):
        a,b = map(int,input().split(" "))
        a+=1
        b+=1
        if (b-a >= 5):
            sWill = s
            sWill += change(a,a)
            sWill += change(b,b)
            arr[a],arr[b] = arr[b],arr[a]
            sWill -= change( a,a)
            sWill -= change(b,b)
            s = sWill
        else:
            # print('here')
            sWill = s
            sWill+=change(a,b)
            # print('this shit:', change(arr,a,b))
            arr[a],arr[b] = arr[b],arr[a]
            sWill-=change(a,b)
            s = sWill
        _sys.stdout.write(str(s) + "\n")


import sys as _sys
# ans = []

def input():
    result = _sys.stdin.readline()
    assert result[-1] == "\n"
    return result[:-1]

def change(i,i1):
    totChange = 0
    for g in range(i-1, i1+2):
        if arr[g] < arr[g-1] and arr[g] < arr[g+1]:
            totChange+=arr[i]
        elif arr[g] > arr[g-1] and arr[g] > arr[g+1]:
            totChange -= arr[g]
    return totChange

arr = []
for _ in range(int(input())):
    n,q = list(map(int,input().split("")))
    arr = [-99,-98] + list(map(int,input().split())) + [-98,-99]
    picked = []
    flag = False
    for i in range(2,n+2):

        if not flag:
            if arr[i] > arr[i-1] and arr[i] > arr[i+1]:
                picked.append(arr[i])
                flag = not flag
        else:
            if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
                picked.append(arr[i])
                flag = not flag
    s = 0
    flag = True
    for i in range(len(picked)):
        if flag:
            s+=picked[i]
        else:
            s-=picked[i]
        flag = not flag
    _sys.stdout.write(str(s) + "\n")
    for i in range(q):
        a,b = map(int,input().split(""))
        a+=1
        b+=1
        if (b-a >= 5):
            sWill = s
            sWill += change(a,a)
            sWill += change(b,b)
            arr[a],arr[b] = arr[b],arr[a]
            sWill -= change( a,a)
            sWill -= change(b,b)
            s = sWill
        else:
            # print('here')
            sWill = s
            sWill+=change(a,b)
            # print('this shit:', change(arr,a,b))
            arr[a],arr[b] = arr[b],arr[a]
            sWill-=change(a,b)
            s = sWill
        _sys.stdout.write(str(s) + "\n")


from math import inf as _inf
import sys as _sys
from io import StringIO
output = StringIO()
# ans = []

def input():
    result = _sys.stdin.readline()
    assert result[-1] == "\n"
    return result[:-1]

def change(arr,i,i1):
    totChange = 0
    for i in range(i-1, i1+2):
        if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
            totChange+=arr[i]
        elif arr[i] > arr[i-1] and arr[i] > arr[i+1]:
            totChange -= arr[i]
    return totChange

for _ in range(int(input())):
    n,q = list(map(int,input().split()))
    arr = [-999999999999,-999999999998] + list(map(int,input().split())) + [-99999999998,-99999999999]
    picked = []
    flag = False
    for i in range(2,n+2):

        if not flag:
            if arr[i] > arr[i-1] and arr[i] > arr[i+1]:
                picked.append(arr[i])
                flag = not flag
        else:
            if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
                picked.append(arr[i])
                flag = not flag
    s = 0
    flag = True
    for i in range(len(picked)):
        if flag:
            s+=picked[i]
        else:
            s-=picked[i]
        flag = not flag
    output.write(str(s) + "\n")
    for i in range(q):
        a,b = list(map(int,input().split()))
        a+=1
        b+=1
        if (b-a >= 5):
            sWill = s
            sWill += change(arr,a,a)
            sWill += change(arr,b,b)
            arr[a],arr[b] = arr[b],arr[a]
            sWill -= change(arr, a,a)
            sWill -= change(arr, b,b)
            s = sWill
        else:
            # print('here')
            sWill = s
            sWill+=change(arr,a,b)
            # print('this shit:', change(arr,a,b))
            arr[a],arr[b] = arr[b],arr[a]
            sWill-=change(arr,a,b)
            s = sWill
        output.write(str(s) + '\n')
_sys.stdout.write(output.getvalue())


from math import inf as _inf
import sys as _sys
ans = []

def input():
    result = _sys.stdin.readline()
    assert result[-1] == "\n"
    return result[:-1]

def change(arr,i,i1):
    totChange = 0
    for i in range(i-1, i1+2):
        if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
            totChange+=arr[i]
        elif arr[i] > arr[i-1] and arr[i] > arr[i+1]:
            totChange -= arr[i]
    return totChange

for _ in range(int(input())):
    n,q = list(map(int,input().split()))
    arr = [-999999999999,-999999999998] + list(map(int,input().split())) + [-99999999998,-99999999999]
    picked = []
    flag = False
    for i in range(2,n+2):

        if not flag:
            if arr[i] > arr[i-1] and arr[i] > arr[i+1]:
                picked.append(arr[i])
                flag = not flag
        else:
            if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
                picked.append(arr[i])
                flag = not flag
    s = 0
    flag = True
    for i in range(len(picked)):
        if flag:
            s+=picked[i]
        else:
            s-=picked[i]
        flag = not flag
    ans+=[s]
    for i in range(q):
        a,b = list(map(int,input().split()))
        a+=1
        b+=1
        if (b-a >= 5):
            sWill = s
            sWill += change(arr,a,a)
            sWill += change(arr,b,b)
            arr[a],arr[b] = arr[b],arr[a]
            sWill -= change(arr, a,a)
            sWill -= change(arr, b,b)
            s = sWill
        else:
            # print('here')
            sWill = s
            sWill+=change(arr,a,b)
            # print('this shit:', change(arr,a,b))
            arr[a],arr[b] = arr[b],arr[a]
            sWill-=change(arr,a,b)
            s = sWill
            # print('this shit after:', change(arr,a,b))
        ans+=[s]
print(*ans,sep="\n")


def change(arr,i,i1):
    totChange = 0
    for i in range(i-1, i1+2):
        if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
            totChange+=arr[i]
        elif arr[i] > arr[i-1] and arr[i] > arr[i+1]:
            totChange -= arr[i]
    return totChange

for _ in range(int(input())):
    n,q = list(map(int,input().split()))
    arr = [-999999999999,-999999999998] + list(map(int,input().split())) + [-99999999998,-99999999999]
    picked = []
    flag = False
    for i in range(2,n+2):

        if not flag:
            if arr[i] > arr[i-1] and arr[i] > arr[i+1]:
                picked.append(arr[i])
                flag = not flag
        else:
            if arr[i] < arr[i-1] and arr[i] < arr[i+1]:
                picked.append(arr[i])
                flag = not flag
    s = 0
    flag = True
    for i in range(len(picked)):
        if flag:
            s+=picked[i]
        else:
            s-=picked[i]
        flag = not flag
    print(s)
    for i in range(q):
        a,b = list(map(int,input().split()))
        a+=1
        b+=1
        if (b-a >= 5):
            sWill = s
            sWill += change(arr,a,a)
            sWill += change(arr,b,b)
            arr[a],arr[b] = arr[b],arr[a]
            sWill -= change(arr, a,a)
            sWill -= change(arr, b,b)
            s = sWill
        else:
            # print('here')
            sWill = s
            sWill+=change(arr,a,b)
            # print('this shit:', change(arr,a,b))
            arr[a],arr[b] = arr[b],arr[a]
            sWill-=change(arr,a,b)
            s = sWill
            # print('this shit after:', change(arr,a,b))
        print(s)