#include<iostream>

using namespace std;

int a[20000][20000];
int n,m;
int S[100000];
int L,R,i,j;
int P,V,X,Y,Z,T;


int main()
{
    cin>>n>>m;
    int o,k;
    for(o=0;o<m;o++)
        cin>>a[0][o];

    for(o=1;o<n;o++)
    {
        cin>>P>>X>>Y>>V>>Z>>T;
        P--;
        L=((X+S[P])%m);
        R=((Y+S[P])%m);
        i=((Z+S[P])%m);
        j=((T+S[P])%m);

        //cout<<"FINDING"<<endl;
        //cout<<L<<' '<<R<<' '<<i<<' '<<j<<' '<<V<<endl;
        for(k=0;k<L;k++)
        {
            a[o][k]=a[P][k];
            if(k>=i && k<=j)S[o]+=a[o][k];

        }
        for(k=L;k<=R;k++)
        {
            a[o][k]=a[P][k]+V;
            if(k>=i && k<=j)S[o]+=a[o][k];
        }
        for(k=R+1;k<n;k++)
        {
            a[o][k]=a[P][k];
            if(k>=i && k<=j)S[o]+=a[o][k];
        }
    }

    for(o=1;o<n;o++)
        cout<<S[o]<<endl;

    return 0;
}


/*
4 4
3 6 7 5
1 2 3 1 0 1
2 1 2 6 2 2
1 0 2 8 0 3
*/


















