#include <iostream>
#include <vector>
#define MAXN 100001
using namespace std;

int main(){
    int N,M,A,V,L,R,X,Y,Z,T,S=0,P,temp;
    vector<int> mr;
    cin>>N>>M;
    mr.resize(M);
    for(int i=0;i<M;i++){
        cin>>temp;
        mr[i]=temp;
        //cout<<temp;
    }
    for(int i=1;i<N;i++){
           // cout<<"--------------";
        cin>>P>>X>>Y>>V>>Z>>T;
        //cout<<(X+S)%M<<"---"<<(Y+S)%M<<" "<<Y<<" "<<S<<" "<<Y+S<<endl;
        for(int j=(X+S)%M;j<=(Y+S)%M;j++){
            mr[j]+=V;
            //cout<<j<<" "<<V+mr[j]<<endl;
        }
        int from=(Z+S)%M,to=(T+S)%M;
        S=0;
        //cout<<from<<"---"<<to<<endl;
        for(int j=from; j<= to;j++){
            S+=mr[j];
            //cout<<S<<endl;
        }
        cout<<S<<endl;
    }

    return 0;
}
