#include <fstream>
#include <iostream>
#include <cstring>

using namespace std;


#define FANCY
//#define HOME

#ifdef HOME
ifstream in("ants.in");
#define cin in
#endif // HOME

const int SZ = 1 << 13;
const int MAX_M = 100000 + 11;
const int MAX_N = 100000 + 11;

typedef long long LL;

typedef int iint;

int A[MAX_M];
int n, m;

struct AIBasic {

    #ifndef FANCY

    iint v[SZ];

    #else

    iint * v;

    AIBasic() {
        v = new iint[SZ];
        for(int i = 0 ; i < SZ ; ++i)
            v[i] = 0;
    }

    #endif

    void build(const int node, const int st, const int dr)
    {
        if(st == dr) {
            v[node] = A[st];
        } else {
            const int mid = (st + dr) / 2;
            build(2 * node    , st     , mid);
            build(2 * node + 1, mid + 1, dr );

            v[node] = v[2 * node] + v[2 * node + 1];
        }
    }

    void build()
    {
        build(1, 1, m);
    }

    iint sum(const int node, const int st, const int dr, const int lo, const int hi)
    {
        iint ret = 0;
        if(lo <= st && dr <= hi) {
            ret = v[node];
        } else {
            const int mid = (st + dr) / 2;
            if(lo <= mid)
                ret += sum(2 * node    , st     , mid, lo, hi);

            if(mid + 1 <= hi)
                ret += sum(2 * node + 1, mid + 1, dr , lo, hi);
        }
        return ret;
    }

    iint sum(const int lo, const int hi)
    {
        return sum(1, 1, m, lo, hi);
    }

};

struct AIB {

    #ifndef FANCY

    iint v[SZ];
    iint sum[SZ];

    #else

    iint * v;
    iint * sum;

    AIB() {
        v = new iint[SZ];
        sum = new iint[SZ];
        for(int i = 0 ; i < SZ ; ++i) {
            v[i] = 0;
            sum[i] = 0;
        }
    }
    #endif

    void lazyUpdate(const int node, const int st, const int dr, const int lo, const int hi, const int val)
    {
        if(lo <= st && dr <= hi) {
            v[node] += val;
        } else {
            const int mid = (st + dr) / 2;

            if(lo <= mid)
                lazyUpdate(2 * node    , st     , mid, lo, hi, val);

            if(mid + 1 <= hi)
                lazyUpdate(2 * node + 1, mid + 1, dr, lo, hi, val);

        }
        sum[node] = v[node] * (dr - st + 1) + sum[2 * node] + sum[2 * node + 1];
    }

    void update(const int lo, const int hi, const int val)
    {
        lazyUpdate(1, 1, m, lo, hi, val);
    }

    iint lazyQuery(const int node, const int st, const int dr, const int lo, const int hi)
    {
        iint ret = 0;
        if(lo <= st && dr <= hi) {
            ret = sum[node];
        } else {
            const int mid = (st + dr) / 2;
            if(lo <= mid)
                ret += lazyQuery(2 * node    , st     , mid, lo, hi);

            if(mid + 1 <= hi)
                ret += lazyQuery(2 * node + 1, mid + 1, dr , lo, hi);

            ret += v[node] * (min(hi, dr) - max(st, lo) + 1);
        }
        return ret;
    }

    iint query(const int lo, const int hi)
    {
        return lazyQuery(1, 1, m, lo, hi);
    }

    void operator=(const AIB *c)
    {
        for(int i = 0 ; i < SZ ; ++i) {
            v[i] = c->v[i];
            sum[i] = c->sum[i];
        }
    }
    void operator=(const AIB &c)
    {
        for(int i = 0 ; i < SZ ; ++i) {
            v[i] = c.v[i];
            sum[i] = c.sum[i];
        }
    }
};

int P, X, Y, V, Z, T;
int N, M;
iint S;

const int SMALL = 101;

AIBasic *init = new AIBasic;

AIB *t = new AIB[SMALL];

AIB *prev = new AIB;
AIB *now = new AIB;

int at = 1;

AIB nth(const int n)
{

    if(n == at)
        return *prev;

    if(n < 101)
        return (t[n]);

}

void updateNth(const int n)
{
    *prev = *now;
    at = n;
    t[n] = now;
}

iint query(const int i, const int j)
{
    return now->query(i, j) + init->sum(i, j);
}

int main()
{
    cin >> n >> m;
    N = n;
    M = m;
    for(int i = 1 ; i <= m ; ++i)
        cin >> A[i];
    init->build();

    for(int _i = 2 ; _i <= n ; ++_i) {
        cin >> P >> X >> Y >> V >> Z >> T;

        const int L = ((X + S) % M) + 1,
                  R = ((Y + S) % M) + 1,
                  i = ((Z + S) % M) + 1,
                  j = ((T + S) % M) + 1;

        *now = nth(P);

        now->update(L, R, V);
        updateNth(_i);

        S = query(i, j);
        cout << S << "\n";
    }
    return 0;
}
