#include<iostream>
#include<stdio.h>
#include<cstdlib>
using namespace std ;

int n , q ;
int WL ;
int WR ;
int PRL ;
int PRR ;
long long a[ 100007 ] ;
long long pref[ 100007 ] ;
long long tr[ 500007 ] ;
long long rem[ 1007 ][ 1007 ] ;
int LEAVES ;

void slow ( ) {
	int i ;
	for ( i = 1 ; i <= n ; i ++ ) {
		scanf ( "%d" , &a[ i ] ) ;
		rem[ 1 ][ i ] = a[ i ] ;
	}
	int p , x , y , z , t , v ;
	long long s = 0 ;
	int ind = 2 ;
	q -- ;
	while ( q != 0 ) {
		q -- ;
		scanf ( "%d%d%d%d%d%d" , &p , &x , &y , &v , &z , &t ) ;
		WL = ( ( x + s ) % n ) + 1 ;
		WR = ( ( y + s ) % n ) + 1 ;
		PRL = ( ( z + s ) % n ) + 1 ;
		PRR = ( ( t + s ) % n ) + 1 ;
		for ( i = 1 ; i <= n ; i ++ ) {
			rem[ ind ][ i ] = rem[ p ][ i ] ;
		}
		for ( i = WL ; i <= WR ; i ++ ) {
			rem[ ind ][ i ] += v ;
		}
		s = 0 ;
		for ( i = PRL ; i <= PRR ; i ++ ) {
			s += rem[ ind ][ i ] ;
		}
		printf ( "%lld\n" , s ) ;
		//cout << s << "\n" ;
		ind ++ ;
	}
}

void goback ( int where , int val ) {
	while ( where != 0 ) {
		tr[ where ] += val ;
		where /= 2 ;
	}
}

void update ( int where , int IL , int IR , int CURL , int CURR , int val ) {
	if ( IL == CURL && IR == CURR ) {
		//tr[ where ] += val ;
		goback ( where , val ) ;
		return ;
	}
	int mid = ( IL + IR ) / 2 ;
	if ( CURL <= mid ) {
		update ( 2 * where , IL , mid , CURL , min ( mid , CURR ) , val ) ;
	}
	if ( CURR > mid ) {
		update ( 2 * where + 1 , mid + 1 , IR , max ( mid + 1 , CURL ) , CURR , val ) ;
	}
}

long long get ( int where , int IL , int IR , int CURL , int CURR , long long add ) {
	if ( tr[ where ] == 0 ) return 0 ;
	add = tr[ where ] ;
	if ( IL == CURL && IR == CURR ) {
		return ( add * ( CURR - CURL + 1 ) ) ;
	}
	long long ret = 0 ;
	int mid = ( IL + IR ) / 2 ; 
	if ( CURL <= mid ) {
		ret += get ( 2 * where , IL , mid , CURL , min ( mid , CURR ) , add ) ;
	}
	if ( CURR > mid ) {
		ret += get ( 2 * where + 1 , mid + 1 , IR , max ( mid + 1 , CURL ) , CURR , add ) ;
	}
	return ret ;
}

int main ( ) {
	scanf ( "%d%d" , &q , &n ) ;
	// off hora, seriozno li pyrvo sa zaqvkite :D
	if ( n <= 1000 && q <= 1000 ) {
		slow ( ) ;
		return 0 ;
	}
	int p , x , y , z , t , v ;
	long long s = 0 ;
	LEAVES = 1 ;
	int i ;
	for ( i = 1 ; i <= n ; i ++ ) {
		scanf ( "%lld" , &a[ i ] ) ;
		pref[ i ] = pref[ i - 1 ] + a[ i ] ; 
	}
	while ( LEAVES < n ) LEAVES *= 2 ;
	q -- ;
	while ( q != 0 ) {
		q -- ;
		scanf ( "%d%d%d%d%d%d" , &p , &x , &y , &v , &z , &t ) ;
		WL = ( ( x + s ) % n ) + 1 ;
		WR = ( ( y + s ) % n ) + 1 ;
		PRL = ( ( z + s ) % n ) + 1 ;
		PRR = ( ( t + s ) % n ) + 1 ;
		update ( 1 , 1 , LEAVES , WL , WR , v ) ;
		s = get ( 1 , 1 , LEAVES , PRL , PRR , 0 ) ;
		s += pref[ PRR ] - pref[ PRL - 1 ] ;
		printf ( "%lld\n" , s ) ;
	}
	return 0 ;
}


