#include<cstdio>
#include<iostream>
using namespace std;
int n,m,s=0,p,x,y,v,z,t,L,R,l,r,st1[1024][1024];
int main()
{
    int i,j;
    //  Subtask #1
    if(n<=1000&&m<=1000)
    {
        scanf("%d%d",&n,&m);
        for(i=1;i<=m;++i){scanf("%d",&st1[1][i]);}
        for(i=2;i<=n;++i)
        {
            scanf("%d%d%d%d%d%d",&p,&x,&y,&v,&z,&t);
            L=(x+s)%m+1;R=(y+s)%m+1;
            l=(z+s)%m+1;r=(t+s)%m+1;
            s=0;
            for(j=1;j<=m;++j)
            {
                st1[i][j]=st1[p][j];
                if(j>=L&&j<=R){st1[i][j]+=v;}
                if(j>=l&&j<=r){s+=st1[i][j];}
            }
            printf("%d\n",s);
        }
        return 0;
    }
    //  Subtask #2
    return 0;
}
