#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cassert>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <set>
#include <map>

using namespace std;

#define mp(a, b) make_pair(a, b)
#define szof(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()

typedef signed long long int int64;
typedef long double real;
typedef pair<int, int> pii;

const int INF = INT_MAX;
const int64 LINF = LLONG_MAX;
const real EPS = 1e-9;
const int MAXN = 100001;
const int ALPH = 26;

#ifdef DEBUG
  #define _show(a) cerr << #a << " = " << a << endl;
#else
  #define _show(a) (void)42
#endif

struct Node;

vector<Node*> node_list;

struct Node {
  int l, r, m;
  int64 sum, add;
  
  Node *lson, *rson;
  
  void update() {
    sum = lson->sum + rson->sum;
  }
  
  void push() {
    if (add == 0) {
      return;
    }
    
    if (lson) {
      lson->sum += add * (lson->r - lson->l + 1);
      lson->add += add;
    
      rson->sum += add * (rson->r - rson->l + 1);
      rson->add += add;
    }
    
    add = 0;
  }
  
  Node(int l, int r, vector<int> &init)
  : l(l), r(r), m((l + r) / 2), sum(0), add(0), lson(0), rson(0) {
    node_list.push_back(this);
    
    if (l == r) {
      sum = init[l];
      return;
    }
    
    lson = new Node(l, m, init);
    rson = new Node(m + 1, r, init);
    
    update();
  }
  
  Node(Node const *src)
  : l(src->l), r(src->r), m(src->m), sum(src->sum), add(src->add), lson(src->lson), rson(src->rson) {
    node_list.push_back(this);
  }
  
  int64 get(int tl, int tr) {
    if (tr < l || r < tl) {
      return 0;
    }
    
    if (tl <= l && r <= tr) {
      return sum;
    }
    
    lson = new Node(lson);
    rson = new Node(rson);
    
    push();
    
    return lson->get(tl, tr) + rson->get(tl, tr);
  }
  
  void set(int tl, int tr, int64 val) {
    if (tr < l || r < tl) {
      return;
    }
    
    if (tl <= l && r <= tr) {
      sum += val * (r - l + 1);
      add += val;
      return;
    }
    
    lson = new Node(lson);
    rson = new Node(rson);
    
    push();
    
    lson->set(tl, tr, val);
    rson->set(tl, tr, val);
    
    update();
  }
};

int n, m;
vector<int> C;
vector<Node*> tree;

int main() {
  ios_base::sync_with_stdio(false);
  
  cin >> n >> m;
  C.resize(m);
  
  int64 s = 0;
  for (int i = 0; i < m; ++i) {
    cin >> C[i];
  }
  
  tree.resize(n);
  tree[0] = new Node(0, m - 1, C);
  
  for (int i = 1; i < n; ++i) {
    int p, x, y, v, z, t;
    cin >> p >> x >> y >> v >> z >> t;
    --p;
    
    int l = (x + s) % m;
    int r = (y + s) % m;
    int tl = (z + s) % m;
    int tr = (t + s) % m;
    
    tree[i] = new Node(tree[p]);
    tree[i]->set(l, r, v);
    
    tree[i] = new Node(tree[i]);
    int64 ans = tree[i]->get(tl, tr);
    
    cout << ans << '\n';
    s = ans;
  }
  
  for (int i = 0; i < szof(node_list); ++i) {
    delete node_list[i];
  }
}
