#include <cassert>

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

#define int64 long long

const int kMaxN = 100005;

const int BufferSize = 100000;
int BufferInd = BufferSize - 1;
char Buffer[BufferSize];

inline void verf() {
    if (++BufferInd == BufferSize) {
        BufferInd = 0; 
        cin.read(Buffer, BufferSize);
    }
}
#define CharB Buffer[BufferInd]
#define CharOk (('0' <= CharB and CharB <= '9')?(1):(0))

void cit(int &a) {
    verf();
    for (; not CharOk; verf())
        ;
    for (a = 0; CharOk; verf()) {
        a *= 10;
        a += CharB - '0';
    }
    return ;
}

int64 s = 0;

int n, m;
int el[kMaxN];

struct Coord {
    int l, r, i, j;
    Coord() {
        l = r = i = j = 0;
    }
    Coord(int _l, int _r, int _i, int _j) {
        l = _l;
        r = _r;
        i = _i;
        j = _j;
    }
};

struct Village {
    int p, x, y, v, z, t;
    Village() {
        p = x = y = v = z = t = 0;
    }
    Village(int a[6]) {
        p = a[0];
        x = a[1];
        y = a[2];
        v = a[3];
        z = a[4];
        t = a[5];
    }
    Coord getCoord() {
        return Coord(int(((x + s) % m) + 1),
            int(((y + s) % m) + 1),
            int(((z + s) % m) + 1),
            int(((t + s) % m) + 1)
        );
    }
} Query[kMaxN];

struct AintNode {
    int64 lazy, sum;
    AintNode *Left, *Right;
    AintNode() {
        lazy = sum = 0;
        Left = NULL;
        Right = NULL;
    }
    void Update(int st, int dr) {
        if (st == dr) {
            sum = lazy;
        } else {
            sum = Left->sum + Right->sum + 1LL * (dr - st + 1) * lazy;
        }
    }
} *AintBeg[kMaxN];

void CreateAint(AintNode *nod, int st, int dr) {
    if (st == dr) {
        nod->lazy = el[st];
        nod->sum = el[st];
        return ;
    } else {
        AintNode *l = new AintNode(), *r = new AintNode();
        nod->Left = l;
        nod->Right = r;
        
        int m = (st + dr) / 2;
        CreateAint(l, st, m);
        CreateAint(r, m + 1, dr);
        nod->Update(st, dr);
    }
    //cerr << st << '\t' << dr << '\t' << nod->Left << '\t' << nod->Right << '\n';
}

int intersection(int st, int dr, int c1, int c2) {
    if (st < c1)
        st = c1;
    if (dr > c2)
        dr = c2;
    assert(dr >= st);
    return dr - st + 1;
}

int64 AintQuery(AintNode *nod, int st, int dr, int c1, int c2) {
    if (dr < c1 or c2 < st)
        return 0;
    if (c1 <= st and dr <= c2)
        return nod->sum;
    int m = (st + dr) / 2;
    int64 rez = 1LL * intersection(st, dr, c1, c2) * nod->lazy;
    rez += AintQuery(nod->Left, st, m, c1, c2);
    rez += AintQuery(nod->Right, m + 1, dr, c1, c2);
    return rez;
}

void AintInsert(AintNode *copy_nod, AintNode *target_nod, int st, int dr, int c1, int c2, int v) {
    *target_nod = *copy_nod;
    //cerr << st << '\t' << dr << '\t' << c1 << '\t' << c2 << '\n';
    //cerr << copy_nod->Left << '\t' << copy_nod->Right << '\n';
    if (c1 <= st and dr <= c2) {
        target_nod->lazy += v;
        //cerr << copy_nod->Left << "!!\n";
        target_nod->Update(st, dr);
    } else {
        int m = (st + dr) / 2;
        if (c1 <= m) {
            target_nod->Left = new AintNode();
            AintInsert(copy_nod->Left, target_nod->Left, st, m, c1, c2, v);
        }
        if (m + 1 <= c2) {
            target_nod->Right = new AintNode();
            AintInsert(copy_nod->Right, target_nod->Right, m + 1, dr, c1, c2, v);
        }
        target_nod->Update(st, dr);
    }
}

int main() {
    cit(n); cit(m);
    for (int i = 1; i <= m; ++i)
        cit(el[i]);
    for (int i = 2; i <= n; ++i) {
        int a[6];
        for (int j = 0; j < 6; ++j)
            cit(a[j]);
        Query[i] = Village(a);
    }
    AintBeg[1] = new AintNode();
    CreateAint(AintBeg[1], 1, m);
    
    for (int t = 2; t <= n; ++t) {
        AintBeg[t] = new AintNode();
        Coord c = Query[t].getCoord();
        AintInsert(AintBeg[Query[t].p], AintBeg[t], 1, m, c.l, c.r, Query[t].v);
        s = AintQuery(AintBeg[t], 1, m, c.i, c.j);
        cout << s << '\n';
    }
    return 0;
}