#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long Int;

int n,m;
Int a[1001][1001];

int main()
{
    int i,j;
    Int S=0,P,X,Y,V,Z,T;
    Int L,R;
    Int pL,pR;
    
    scanf("%d %d",&n,&m);
    
    for (i=1;i<=m;i++)
    {
        scanf("%lld",&a[1][i]);
    }
    
    for (i=2;i<=n;i++)
    {
        scanf("%lld %lld %lld %lld %lld %lld",&P,&X,&Y,&V,&Z,&T);
        
        L=((X+S)%m)+1;
        R=((Y+S)%m)+1;
        pL=((Z+S)%m)+1;
        pR=((T+S)%m)+1;
        
        for (j=1;j<=m;j++)
        {
            if (j>=L && j<=R)
            {
                a[i][j]=a[P][j]+(Int)V;
            }
            else
            {
                a[i][j]=a[P][j];
            }
        }
        
        S=0;
        for (j=pL;j<=pR;j++)
        {
            S+=a[i][j];
        }
        
        printf("%lld\n",S);
    }
    
    return 0;
}