#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

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

int main() {
  ios_base::sync_with_stdio(false);
  
  cin >> n >> m;
  C.resize(n, vector<int64> (m));
  
  int64 s = 0;
  for (int i = 0; i < m; ++i) {
    cin >> C[0][i];
  }
  
  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;
    
    for (int j = 0; j < m; ++j) {
      C[i][j] = C[p][j];
    }
    
    for (int j = l; j <= r; ++j) {
      C[i][j] += v;
    }
    
    int64 ans = 0;
    for (int j = tl; j <= tr; ++j) {
      ans += C[i][j];
    }
    
    cout << ans << '\n';
    s = ans;
  }
}
