#include<iostream>
//#include<fstream>
using namespace std;
//ifstream cin("test.in");
//ofstream cout("test.out");
const int size=1<<12;
char buff[size]; int pos=size+1;
bool rable(char &c){return ('0'<=c && c<='9');}
void Read(int &x){
    x=0;
    if(pos>=size){cin.read(buff,size);pos=0;}
    while(!rable(buff[pos])){pos++;if(pos>=size){cin.read(buff,size);pos=0;}}
    while(rable(buff[pos])){x=x*10+int(buff[pos++])-'0';if(pos>=size){cin.read(buff,size);pos=0;}}
}
const int Nmax = 100002;
int A[2][Nmax];
int N,M,L[Nmax],R[Nmax],I,J,S;
int P,X,Y,V[Nmax],Z,T;
int IND=1,Q[2][Nmax];
int Tr[Nmax];

int lsb(int &x){return (x&(-x));}
void update(int X[],int x,int val){
    while(x<=N){
        X[x]+=val;
        x+=lsb(x);
    }
}
int query(int X[],int x){
    int s=0;
    while(x){
        s+=X[x];
        x-=lsb(x);
    }
    return s;
}
void range_update(int X[2][Nmax],int x,int y,int val){
    update(X[0],x,val);
    update(X[0],y+1,-val);
    int sz=y-x+1;
    update(X[1],x,-val*(x-1));
    update(X[1],y+1,val*sz+val*(x-1));
}
int monoquery(int X[2][Nmax],int x){
    return x*query(X[0],x)+query(X[1],x);
}
int range_query(int X[2][Nmax],int x,int y){
    return monoquery(X,y)-monoquery(X,x-1);
}
void updQ(int p,int coef){
    while(p!=1){
        range_update(Q,L[p],R[p],coef*V[p]);
        p=Tr[p];
    }
}
int main(){
    Read(M),Read(N);
    for(int i=1;i<=N;i++){
        Read(X);
        range_update(A,i,i,X);
    }
    //for(int j=1;j<=N;j++) cout<<range_query(A,j,j)<<' ';cout<<'\n';
    for(int i=1;i<M;i++){
        ++IND;
        Read(P),Read(X),Read(Y),Read(V[IND]),Read(Z),Read(T);
        Tr[IND]=P;
        L[IND]=((X+S)%M)+1;
        R[IND]=((Y+S)%M)+1;
        I=((Z+S)%M)+1;
        J=((T+S)%M)+1;
        //cout<<L[IND]<<' '<<R[IND]<<' '<<V[IND]<<' '<<I<<' '<<J<<'\n';
        updQ(IND,1);
        //range_update(A,L[IND],R[IND],V[IND]);
        S=range_query(Q,I,J) + range_query(A,I,J);
        cout<<S<<'\n';
        //for(int j=1;j<=N;j++) cout<< range_query(Q,j,j) + range_query(A,j,j) <<' ';cout<<'\n';
        updQ(IND,-1);
    }
    return 0;
}
