/**
*@task: ants
*@competition: Autumn 2014, Shumen
*@author: Vasil Sarafov
*@time: 23.11.2014, Shumen
**/
#include <iostream>
#include <cstdio>

#define space " "
#define ln "\n"

typedef long long int LL;

const LL MAX_N = (LL)(1e5) + 10;

struct IntervalTreeNode {
	LL total,
	   lazy;
};

LL n, m,
	arr[MAX_N];
IntervalTreeNode tree[3 * MAX_N];

void build(LL node, LL lhs, LL rhs) {
	if (lhs > rhs)
		return;
	if (lhs == rhs) {
		tree[node].total = arr[lhs];
		return;
	}
	LL next = node << 1,
	   mid = (lhs + rhs) >> 1;
	build(next, lhs, mid);
	build(next + 1, mid + 1, rhs);
	tree[node].total = tree[next].total + tree[next + 1].total;
	return;
} 

void update(LL node, LL lhs, LL rhs, 
	LL x, LL y, LL val) {
	if (lhs > rhs)
		return;
	if (lhs > y || rhs < x)
		return;
	if (tree[node].lazy) {
		if (lhs != rhs) {
			LL next = node << 1;
			tree[next].lazy += tree[node].lazy;
			tree[next + 1].lazy += tree[node].lazy;
		}
		tree[node].total += tree[node].lazy;
		tree[node].lazy = 0;
	}
	if (x <= lhs && rhs <= y) {
		if (lhs != rhs) {
			LL next = node << 1;
			tree[next].lazy += val;
			tree[next + 1].lazy += val;
		}
		tree[node].total += val;
		return;
	}
	
	LL next = node << 1,
	   mid = (lhs + rhs) >> 1;
	update(next, lhs, mid, x, y, val);
	update(next + 1, mid + 1, rhs, x, y, val);
	tree[node].total = tree[next].total + tree[next + 1].total;
	return;	 
}

LL getSum(LL node, LL lhs, LL rhs, LL x, LL y) {
	if (lhs > rhs)
		return 0LL;
	if (lhs > y || rhs < x)
		return 0LL;
	if (tree[node].lazy) {
		if (lhs != rhs) {
			LL next = node << 1;
			tree[next].lazy += tree[node].lazy;
			tree[next + 1].lazy += tree[node].lazy;
		}
		tree[node].total += tree[node].lazy;
		tree[node].lazy = 0;
	} 
	if (x <= lhs && rhs <= y)
		return tree[node].total;
		
	LL next = node << 1,
	   mid = (lhs + rhs) >> 1,
	   lc = getSum(next, lhs, mid, x, y),
	   rc = getSum(next + 1, mid + 1, rhs, x, y),
	   ret = lc + rc;
	return ret;
}

int main(int argc, char **argv) {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
	scanf("%lld %lld", &n, &m);
	for (int i = 1; i <= m; i++)
		scanf("%lld", &arr[i]);
	build(1, 1, m);
	LL ans = 0LL;
	for (int q = 1; q < n; q++) {
		LL oldCity, lhs1, rhs1, value, lhs2, rhs2;
		scanf("%lld", &oldCity);
		scanf("%lld %lld", &lhs1, &rhs1);
		scanf("%lld", &value);
		scanf("%lld %lld", &lhs2, &rhs2);
		lhs1 = ((lhs1 + ans) % m) + 1;
		rhs1 = ((rhs1 + ans) % m) + 1;
		lhs2 = ((lhs2 + ans) % m) + 1;
		rhs2 = ((rhs2 + ans) % m) + 1;
		update(1, 1, m, lhs1, rhs1, value);
		ans = getSum(1, 1, m, lhs2, rhs2);
		printf("%lld", ans);
		printf(ln);
	} 
	return 0;
}
/*
4 4
3 6 7 5
1 2 3 1 0 1
2 1 2 6 2 2
3 1 2 0 0 3

2 4
3 6 7 5
1 2 3 1 0 1

5 10
1 2 3 4 5 6 7 8 9 10
-1 1 10 0 1 10
-1 1 6 10 5 10
-1 3 7 50 7 9
-1 1 1 0 10 10
*/
