#include <fstream>
#include <iostream>

using namespace std;

//#define HOME

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

const int SZ = 1 << 17;
const int MAX_M = 100000 + 1;
const int MAX_N = 100000 + 1;

const int CHUNK_SIZE = 370;
const int SRT = MAX_N / CHUNK_SIZE;

int A[MAX_M];
int n, m;

struct AIBasic {
    int v[SZ];
    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);
    }

    int sum(const int node, const int st, const int dr, const int lo, const int hi)
    {
        int 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;
    }

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

};

struct AIB {

    int v[SZ];
    int sum[SZ];

    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);
    }

    int lazyQuery(const int node, const int st, const int dr, const int lo, const int hi)
    {
        int 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;
    }

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

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

AIBasic init;

AIB root[SRT];
int   id[SRT];

AIB prev;
AIB now;

int at = 1;
int chunk = 0;
int _at;

AIB nth(const int n)
{
    if(n == at)
        return prev;
}

void updateNth(const int n)
{
    prev = now;
    at = n;
    ++_at;
    if(_at == CHUNK_SIZE) {
        ++chunk;
        root[chunk] = now;
        id  [chunk] = at;
        _at = 0;
    }
}

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

int Pi[MAX_N],
    Li[MAX_N],
    Ri[MAX_N],
    Vi[MAX_N],
    ii[MAX_N],
    ji[MAX_N];

int main()
{
    id[0] = 1;
    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;

        Pi[i] = P,
        Li[i] = L,
        Ri[i] = R,
        Vi[i] = V,
        ii[i] = i,
        ji[i] = j;

        now = nth(P);

        now.update(L, R, V);
        updateNth(_i);

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