#include<iostream>
#include<stdio.h>
using namespace std;
long long int tr[200000],upd[200000],st,trs[2001][2001],upds[2001][2001],cur;
int change (int ind, int l, int r, int tree) {
    if ((cur==1)&&(upd[ind]==0)) return 0;
    else if ((cur==2)&&(upds[tree][ind]==0)) return 0;
    if (ind<=st) {
       if (cur==1) {
          upd[2*ind+1]+=upd[ind];
          upd[2*ind+2]+=upd[ind];
          }
       else { upds[tree][2*ind+1]+=upds[tree][ind];
              upds[tree][2*ind+2]+=upds[tree][ind]; }
       }
    if (cur==1) {
       tr[ind]+=upd[ind]*(r-l+1);
       upd[ind]=0;
       }
    else { trs[tree][ind]+=upds[tree][ind]*(r-l+1);
           upds[tree][ind]=0; }
    return 0;
}
int update (int ind, int l, int r, int from, int to, int incr, int tree) { //cout << l << " " << r << " " << from << " " << to << endl ;
    int mid;
    change(ind,l,r,tree);
    if ((l==from)&&(r==to)) {
       if (cur==1) upd[ind]=incr;
       else upds[tree][ind]=incr;
       change(ind,l,r,tree);
       return 0;
       }
    mid=(l+r)/2;
    if (from<=mid) update(2*ind+1,l,mid,from,min(to,mid),incr,tree);
    if (to>mid) update(2*ind+2,mid+1,r,max(mid+1,from),to,incr,tree);
    change(2*ind+1,l,r,tree); change(2*ind+2,l,r,tree);
    if (cur==1) tr[ind]=tr[2*ind+1]+tr[2*ind+2];
    else trs[tree][ind]=trs[tree][2*ind+1]+trs[tree][2*ind+2];
    return 0;
}
long long int find (int ind, int l, int r, int from, int to, int tree) { //cout << l << " " << r << " " << from << " " << to << endl ;
              int mid;
              change(ind,l,r,tree);
              if ((l==from)&&(r==to)) {
                 if (cur==1) return tr[ind];
                 else return trs[tree][ind];
                 }
              mid=(l+r)/2;
              if ((from<=mid)&&(to>mid)) return find(2*ind+1,l,mid,from,min(to,mid),tree)+find(2*ind+2,mid+1,r,max(mid+1,from),to,tree);
              else if (from<=mid) return find(2*ind+1,l,mid,from,min(to,mid),tree);
              else if (to>mid) return find(2*ind+2,mid+1,r,max(mid+1,from),to,tree);
              change(2*ind+1,l,r,tree); change(2*ind+2,l,r,tree);
              if (cur==1) tr[ind]=tr[2*ind+1]+tr[2*ind+2];
              else trs[tree][ind]=trs[tree][2*ind+1]+trs[tree][2*ind+2];
              return 0;
}
int main () {
    long long int n,m,s=0,pr,x,y,incr,z,t,l1,r1,l2,r2,i,j;
    scanf("%lld%lld",&n,&m);
    if (m<=1000) cur=2;
    else cur=1;
    st=1;
    for (;;) {
        if (st>=m) break;
        st*=2;
        }
    st--;
    for (i=0; i<m; i++) {
        if (cur==1) scanf("%lld",&tr[st+i]);
        else scanf("%lld",&trs[0][st+i]);
        }
    for (i=st-1; i>=0; i--) {
        if (cur==1) tr[i]=tr[2*i+1]+tr[2*i+2];// cout << tr[i] << " ";
        else trs[0][i]=trs[0][2*i+1]+trs[0][2*i+2];
        }
    for (i=0; i<n-1; i++) {
        scanf("%lld%lld%lld%lld%lld%lld",&pr,&x,&y,&incr,&z,&t);
        l1=(x+s)%m+1; r1=(y+s)%m+1; l2=(z+s)%m+1; r2=(t+s)%m+1;
        l1--; r1--; l2--; r2--;
        if (cur==2) {
           for (j=0; j<st+m; j++) {
               trs[i+1][j]=trs[pr-1][j];
               upds[i+1][j]=upds[pr-1][j]; //cout << trs[i+1][j] << " ";
               }
           }
        //cout << x << " " << s << " " << m << " " << l1 << " " << r1 << " " << l2 << " " << r2 << endl ;
        update(0,0,st,l1,r1,incr,i+1);
        //cout << tr[0] << " ";
        s=find(0,0,st,l2,r2,i+1);
        printf("%lld\n",s);
        //if (i==0) s=12;
        }
    return 0;
}
