#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAXN = 1e5;
const int MAXM = 1e5;

ll n, m;

struct TNode {
    int L, R;
    int left, right;
    ll key;
    ll val;
};

TNode tree[2 * MAXM + 15];
int a[MAXM + 15];
int tc = 0;

int newNode(int L, int R) {
    tree[tc].L = L;
    tree[tc].R = R;
    tree[tc].left = -1;
    tree[tc].right = -1;
    tree[tc].key = 0;
    tree[tc].val = 0;
    
    return tc++;
}

int buildTree(int L, int R) {
    int root = newNode(L, R);
    
    if (R - L == 1) {
        tree[root].key = a[L];
        return root;
    }
    
    int M = (L + R) / 2;    
    int left = tree[root].left = buildTree(L, M);
    int right = tree[root].right = buildTree(M, R);
    
    tree[root].key = tree[left].key + tree[right].key;
    return root;
}

void setVal(int node, ll val) {
    if (node == -1) {
        return;
    }
    
    tree[node].val += val;
}

void push(int node) {
    tree[node].key += tree[node].val * ll(tree[node].R - tree[node].L);
    
    setVal(tree[node].left, tree[node].val);
    setVal(tree[node].right, tree[node].val);
    
    tree[node].val = 0;
}

void update_seq(int node, int v, int L, int R) {
    if (tree[node].R <= L || R <= tree[node].L) {
        return;
    }
    
    if (L <= tree[node].L && tree[node].R <= R) {
        setVal(node, v);
        return;
    }
    
    push(node);
    int left = tree[node].left;
    int right = tree[node].right;
   
    update_seq(left, v, L, R);
    update_seq(right, v, L, R);
    
    tree[node].key = tree[left].key + tree[right].key;
}

ll getSum(int node, int L, int R) {
    if (tree[node].R <= L || R <= tree[node].L) {
        return 0;
    }
    
    push(node);
    if (L <= tree[node].L && tree[node].R <= R) {
        return tree[node].key;
    }
    
    return getSum(tree[node].left, L, R) + getSum(tree[node].right, L, R);
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    scanf("%lld%lld", &n, &m);
 
    if (n <= 1000 && m <= 1000) {
        vector<vector<ll> > b(n, vector<ll> (m));
        for (int i = 0; i < m; i++) {
            cin >> b[0][i];
        }
        
        ll s = 0;
        for (int ii = 1; ii <= n - 1; ii++) {
            ll p, x, y, v, z, t;
            cin >> p >> x >> y >> v >> z >> t;
            
            int L = (x + s) % m, R = (y + s) % m + 1;
            int i = (z + s) % m, j = (t + s) % m + 1;
            
            b[ii] = b[p - 1];
            for (int k = L; k < R; k++) {
                b[ii][k] += v;
            }
            
            ll curs = 0;
            for (int k = i; k < j; k++) {
                curs += b[ii][k];
            }
            
            s = curs;
            cout << s << endl;
        }
        
        return 0;
    }
 
    for (int i = 0; i < m; i++) {
        scanf("%lld", a + i);
    }
    
    buildTree(0, m);
    
    ll s = 0;
    for (int ii = 1; ii <= n - 1; ii++) {
        ll p, x, y, v, z, t;
        cin >> p >> x >> y >> v >> z >> t;
        
        ll L = (x + s) % m, R = (y + s) % m + 1;
        ll i = (z + s) % m, j = (t + s) % m + 1;
        
        update_seq(0, v, L, R);
        s = getSum(0, i, j);
        if (p != i) {
            printf("WTF?\n");
        } else {
            printf("%lld\n", s);
        }
    }
}