#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
using namespace std;


const int MAX_M = 100100;
int v[MAX_M];

struct elem {
    long long sum;
    long long lazy;
    int l;
    int f1, f2;

    elem() {
        sum = lazy = l = 0;
        f1 = f2 = 0;
    }
};

int cat;
int R[MAX_M];
elem arb[5000000];


void build(int poz, int st, int dr) {
    if(st == dr) {
        arb[poz].sum = v[st];
        arb[poz].lazy = 0;
        arb[poz].l = 1;
        arb[poz].f1 = arb[poz].f2 = 0;
        return;
    }

    int mij = (st + dr) / 2;
    arb[poz].f1 = ++cat;
    build(arb[poz].f1, st, mij);
    arb[poz].f2 = ++cat;
    build(arb[poz].f2, mij + 1, dr);

    elem &f1 = arb[arb[poz].f1];
    elem &f2 = arb[arb[poz].f2];

    arb[poz].sum = f1.sum + f2.sum + f1.l * f1.lazy + f2.l * f2.lazy;
    arb[poz].l = f1.l + f2.l;
    arb[poz].lazy = 0;
}

void update(int poz, int ant, int st, int dr, int a,  int b, long long val) {
    if(st >= a && dr <= b) {
        arb[poz].sum = arb[ant].sum;
        arb[poz].l = arb[ant].l;
        arb[poz].lazy = arb[ant].lazy + val;
        arb[poz].f1 = arb[ant].f1;
        arb[poz].f2 = arb[ant].f2;
        return;
    }

    int mij = (st + dr) / 2;
    if(a <= mij) {
        arb[poz].f1 = ++cat;
        update(arb[poz].f1, arb[ant].f1, st, mij, a, b, val);
    }
    else {
        arb[poz].f1 = arb[ant].f1;
    }
    if(b > mij) {
        arb[poz].f2 = ++cat;
        update(arb[poz].f2, arb[ant].f2, mij + 1, dr, a, b, val);
    }
    else {
        arb[poz].f2 = arb[ant].f2;
    }


    elem &f1 = arb[arb[poz].f1];
    elem &f2 = arb[arb[poz].f2];


    arb[poz].sum = f1.sum + f2.sum + f1.l * f1.lazy + f2.l * f2.lazy;
    arb[poz].l = f1.l + f2.l;
    arb[poz].lazy = arb[ant].lazy;

}

long long query(int poz, int st, int dr, int a, int b, long long lz) {
    lz += arb[poz].lazy;
    if(st >= a && dr <= b) {
        return arb[poz].sum + arb[poz].l * lz;
    }

    long long ans = 0;
    int mij = (st + dr) / 2;
    if(a <= mij) {
        ans += query(arb[poz].f1, st, mij, a, b, lz);
    }
    if(b > mij) {
        ans += query(arb[poz].f2, mij + 1, dr, a, b, lz);
    }
    return ans;
}

int main()
{
    //ifstream cin("fis.in");
    //ofstream cout("fis.out");

    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        cin >> v[i];
    }

    int sz;
    for(sz = 1; sz < m; sz *= 2);
    R[1] = ++cat;
    build(1, 1, sz);

    long long s = 0;
    for(int i = 2; i <= n; i++) {
        int p, x, y, z, t;
        long long v;
        cin >> p >> x >> y >> v >> z  >> t;
        int l = (x + s) % m + 1;
        int r = (y + s) % m + 1;
        R[i] = ++cat;
        update(R[i], R[p], 1, sz, l, r, v);

        l = (z + s) % m + 1;
        r = (t + s) % m + 1;
        s = query(R[i], 1, sz, l, r, 0);
        cout << s << '\n';
    }

    return 0;
}
