#include <cstdio>
#include <algorithm>

using namespace std;

const int SQ = 400;

int N, M;
int P[100002], X[100002], Y[100002], V[100002], Z[100002], T[100002];
int L[100002], R[100002];
int A[100002];
long long SUM[100002];
int Tat[100002], nord[100002], wh[100002];
int clc[100002];
bool ok[100002];
long long W[270][100002];

int main()
{
    //freopen("ants.in", "r", stdin);
    //freopen("ants.out", "w", stdout);

    scanf("%d %d", &N, &M);
    for (int i = 1; i <= M; ++i) // M e nr de musuroaie
    {
        scanf("%d", &A[i]);
        SUM[i] = SUM[i - 1] + A[i];
    }

    long long S = 0;
    for (int i = 2; i <= N; ++i)
    {
        scanf("%d %d %d %d %d %d", &P[i], &X[i], &Y[i], &V[i], &Z[i], &T[i]);
        Tat[i] = P[i];
    }

    nord[1] = ++nord[0];
    for (int i = 1; i <= M; ++i)
        W[nord[1]][i] = SUM[i];
    wh[1] = 1;

    ok[1] = true;
    for (int i = 2; i <= N; ++i)
    {
        int now = i;
        bool found = false;

        for (int j = 1; j <= SQ; ++j)
        {
            now = Tat[now];
            if (ok[now])
            {
                found = true;
                break;
            }
        }

        if (!found)
        {
            wh[nord[0]] = i;
            nord[i] = ++nord[0];
            ok[i] = true;
        }
    }

    if (nord[0] > 250)
    {
        int del = nord[0] - 250;
        for (int i = 1; i <= del; ++i)
            clc[i] = 1;
        random_shuffle(clc + 1, clc + nord[0] + 1);

        int oldS = nord[0];
        nord[0] = 0;

        for (int i = 1; i <= oldS; ++i)
        {
            ok[wh[i]] = false;
            if (i == 1 || !clc[i])
            {
                nord[wh[i]] = ++nord[0];
                ok[wh[i]] = true;
            }
        }
    }

    for (int i = 2; i <= N; ++i)
    {
        L[i] = (X[i] + S) % M + 1, R[i] = (Y[i] + S) % M + 1;
        int qi = (Z[i] + S) % M + 1, qj = (T[i] + S) % M + 1;

        S = 0;
        if (ok[i])
        {
            int now = i;
            while (now == i || !ok[now])
            {
                W[nord[i]][L[now]] += V[now];
                W[nord[i]][R[now] + 1] -= V[now];
                now = Tat[now];
            }
            for (int j = 1; j <= M; ++j)
                W[nord[i]][j] += W[nord[i]][j - 1];
            for (int j = 1; j <= M; ++j)
            {
                W[nord[i]][j] += (W[nord[now]][j] - W[nord[now]][j - 1]);
                W[nord[i]][j] += W[nord[i]][j - 1];
            }

            S = W[nord[i]][qj] - W[nord[i]][qi - 1];
        }
        else
        {
            int now = i;
            while (!ok[now])
            {
                int i1 = max(L[now], qi), i2 = min(R[now], qj);
                if (i1 <= i2) S += 1LL * V[now] * (i2 - i1 + 1);
                now = Tat[now];
            }
            S += W[nord[now]][qj] - W[nord[now]][qi - 1];
        }

        printf("%lld\n", S);
    }
}
