#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>
#include <ctime>

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 {
  int64 sum, add;
  int lson, rson;
};

const int MAXNODE = 10000000;

int ptr = 0;
Node nodel[MAXNODE];

void update(const int &ind) {
  nodel[ind].sum = nodel[nodel[ind].lson].sum + nodel[nodel[ind].rson].sum;
}

void push(const int &ind, const int &l, const int &r, const int &m) {
  if (nodel[ind].add == 0) {
    return;
  }
  
  if (nodel[ind].lson != -1) {
    nodel[nodel[ind].lson].sum += nodel[ind].add * (m - l + 1);
    nodel[nodel[ind].lson].add += nodel[ind].add;
  
    nodel[nodel[ind].rson].sum += nodel[ind].add * (r - m);
    nodel[nodel[ind].rson].add += nodel[ind].add;
  }
  
  nodel[ind].add = 0;
}

int ctr = 0;
int createNode(const int &l, const int &r, vector<int> &init) {
  ++ctr;
  
  Node n;
  
  n.sum = 0;
  n.add = 0;
  n.lson = -1, n.rson = -1;
  
  if (l == r) {
    n.sum = init[l];
    nodel[ptr++] = n;
  } else {
    int m = (l + r) / 2;
    n.lson = createNode(l, m, init);
    n.rson = createNode(m + 1, r, init);
    nodel[ptr++] = n;
    
    update(ptr - 1);
  }
  
  return ptr - 1;
}

int createNode(const int &ind) {
  ++ctr;
  
  Node n;
  n.sum = nodel[ind].sum;
  n.add = nodel[ind].add;
  
  n.lson = nodel[ind].lson;
  n.rson = nodel[ind].rson;
  
  nodel[ptr++] = n;
  return ptr - 1;
}

int64 get(const int &ind, const int &l, const int &r, const int &tl, const int &tr) {
  if (tr < l || r < tl) {
    return 0;
  }
  
  if (tl <= l && r <= tr) {
    return nodel[ind].sum;
  }
  
  int m = (l + r) / 2;
  
  if (nodel[ind].add) {
    nodel[ind].lson = createNode(nodel[ind].lson);
    nodel[ind].rson = createNode(nodel[ind].rson);
  
    push(ind, l, r, m);
  }
  
  return get(nodel[ind].lson, l, m, tl, tr) + get(nodel[ind].rson, m + 1, r, tl, tr);
}

inline bool check(const int &l, const int &r, const int &tl, const int &tr) {
  return !(tr < l || r < tl);
}

void setv(const int &ind, const int &l, const int &r, const int &tl, const int &tr, const int64 &val) {
  if (tr < l || r < tl) {
    return;
  }
  
  if (tl <= l && r <= tr) {
    nodel[ind].sum += val * (r - l + 1);
    nodel[ind].add += val;
    return;
  }
  
  int m = (l + r) / 2;
  
  if (check(l, m, tl, tr)) {
    nodel[ind].lson = createNode(nodel[ind].lson);
  }
  
  if (check(m + 1, r, tl, tr)) {
    nodel[ind].rson = createNode(nodel[ind].rson);
  }
  
  push(ind, l, r, m);
  
  setv(nodel[ind].lson, l, m, tl, tr, val);
  setv(nodel[ind].rson, m + 1, r, tl, tr, val);
  update(ind);
}

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

int main() {
  cin >> n >> m;
  C.resize(m);
  
  int64 s = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &C[i]);
  }
  
  tree.resize(n);
  tree[0] = createNode(0, m - 1, C);
  
  for (int i = 1; i < n; ++i) {
    int p, x, y, v, z, t;
    scanf("%d %d %d %d %d %d", &p, &x, &y, &v, &z, &t);
    --p;
    
    int l = x + s;
    if (l >= m) {
      l -= m;
    }
    
    int r = y + s;
    if (r >= m) {
      r -= m;
    }
    
    if (l > r) {
      swap(l, r);
    }
    
    int tl = z + s;
    if (tl >= m) {
      tl -= m;
    }
    
    int tr = t + s;
    if (tr >= m) {
      tr -= m;
    }
    
    if (tl > tr) {
      swap(tl, tr);
    }
    
    tree[i] = createNode(tree[p]);
    setv(tree[i], 0, m - 1, l, r, v);
    
    int64 ans = get(tree[i], 0, m - 1, tl, tr);
    
    printf("%lld\n", ans);
    s = (ans) % m;
  }
  
  #ifdef DEBUG
    cerr << endl << endl << ctr << " Nodes" << endl;
    cerr << endl << endl << 1. * clock() / CLOCKS_PER_SEC << endl;
  #endif
}
