#include<cstdio>
using namespace std;

int n_special, a[100009], N, M, where[100009], depth[100009], P[100009], UL[100009], UR[100009], UV[100009];
long long ANS, arb[400009], sum[100009], s[320][100009];

void lazy (int nod, int st, int dr, int mij)
{
    if (arb[nod])
    {
        arb[nod<<1] += arb[nod];
        sum[nod<<1] += 1LL * arb[nod] * (mij - st + 1);
        arb[(nod<<1) + 1] += arb[nod];
        sum[(nod<<1) + 1] += 1LL * arb[nod] * (dr - mij);
        arb[nod] = 0;
    }
}

void U (int nod, int st, int dr, int x, int y, int V)
{
    if (x<=st && dr <= y)
    {
        arb[nod] += V;
        sum[nod] += 1LL * V * (dr - st + 1);
        return ;
    }
    int mij = (st + dr) >> 1;
    lazy (nod, st, dr, mij);
    if (x <= mij) U (nod<<1, st, mij, x, y, V);
    if (y > mij) U ((nod<<1)+1, mij+1, dr, x, y, V);
    sum[nod] = sum[nod<<1] + sum[(nod<<1)+1];
}

void Q (int nod, int st, int dr, int x, int y)
{
    if (x <= st && dr <= y)
    {
        ANS += sum[nod];
        return ;
    }
    int mij = (st + dr) >> 1;
    lazy (nod, st, dr, mij);
    if (x <= mij) Q (nod<<1, st, mij, x, y);
    if (y > mij) Q ((nod<<1)+1, mij+1, dr, x, y);
    sum[nod] = sum[nod<<1] + sum[(nod<<1)+1];
}

int main()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
for (int i=1; i<=M; i++)
{
    scanf ("%d", &a[i]);
    s[1][i] = s[1][i-1] + a[i];
}

where[1] = 1;
n_special = 1;

ANS = 0;

int lim_dist = 320;

for (int i=2; i<=N; i++)
{
    int X, Y, V, Z, T;
    scanf ("%d %d %d %d %d %d", &P[i], &X, &Y, &V, &Z, &T);
    int L, R, qi, qj;
    L = ((long long) ANS + X) % M + 1;
    R = ((long long) ANS + Y) % M + 1;
    qi = ((long long) ANS + Z) % M + 1;
    qj = ((long long) ANS + T) % M + 1;
    UL[i] = L;
    UR[i] = R;
    UV[i] = V;
    depth[i] = depth[P[i]] + 1;
    if (depth[i] == lim_dist)
    {
        ////O (n)
        where[i] = ++n_special;
        int nod = i;
        while (depth[nod])
        {
            s[n_special][UL[nod]] += UV[nod];
            s[n_special][UR[nod]+1] -= UV[nod];
            nod = P[nod];
        }
        ////acum nod este ala pentru care am precalculat
        for (int j=1; j<=M; j++)
            s[n_special][j] += s[n_special][j-1];
        for (int j=1; j<=M; j++)
            s[n_special][j] += s[n_special][j-1];
        for (int j=1; j<=M; j++)
            s[n_special][j] += s[where[nod]][j];
        depth[i] = 0;
        ANS = s[n_special][qj] - s[n_special][qi-1];
    }
    else
    {
        ////O(dist)log
        int nod = i;
        while (depth[nod])
        {
            U (1, 1, M, UL[nod], UR[nod], UV[nod]);
            nod = P[nod];
        }
        ANS = s[where[nod]][qj] - s[where[nod]][qi-1];
        Q (1, 1, M, qi, qj);
        ///////update inapoi sa curat
        nod = i;
        while (depth[nod])
        {
            U (1, 1, M, UL[nod], UR[nod], -UV[nod]);
            nod = P[nod];
        }
    }
    printf ("%lld\n", ANS);
}

return 0;
}
