#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <list>
using namespace std;
typedef pair<int, int> ii;
typedef unsigned long long int u64;
typedef long long int i64;
const int MAXM = 4000;
const int MAXN = 1000;
int N, M;
int mrav[110000];

u64 S = 0;
struct IT
{
    vector<int> data;
    IT()
    {
        data.resize(M+10);
    }
    int lefty(int pos)
    {
        return pos << 1;
    }
    int righty(int pos)
    {
        return (pos << 1) + 1;
    }
    int get(int from, int to)
    {
        return get(1, 0, N, from, to);
    }
    int get(int pos, int from, int to, int L, int R)
    {
        if(L > to || R < from) return 0;
        if(L <= from && R >= to) { //cout<<"DATA: "<<data[pos]<<", for pos: "<<pos<<endl;
        return data[pos];}
        int left = 0; int right = 0;
        int mid = (from + to) / 2;
        left = get(lefty(pos), from, mid, L, R);
        right = get(righty(pos), mid+1, to, L, R);
        //cout<<"pos: "<<pos<<", from: "<<from<<", to: "<<to<<", L: "<<L<<", R: "<<R<<endl<<", sum: "<<left + right<<endl;cout.flush();
        return left + right;
    }
    void increment(int index, int value)
    {
        increment(1 , 0, N, index, value);
    }
    void increment(int pos, int from, int to, int index, int value)
    {
        //cout<<"pos: "<<pos<<", from: "<<from<<", to: "<<to<<", index: "<<index<<", value: "<<value<<endl;cout.flush();
        if(from == to)
        {
            data[pos] += value;
            //cout<<"pos: "<<pos<<", val: "<<data[pos]<<endl;
            return;
        }
        int mid = (from + to) / 2;
        if(mid < index) increment(righty(pos), mid+1, to, index, value);
        else increment(lefty(pos), from, mid, index, value);
        data[pos] = data[lefty(pos)] + data[righty(pos)];
    }
};
vector<IT> wow;
IT prevIT, secondIT;
int main()
{
    ios::sync_with_stdio(false);
    cin >> N >> M;
    wow.resize(N+10);
    for(int i = 0; i < M; ++i)
    {
        cin >> mrav[i];
        //cout<<"nicrement pos: "<<i+1<<" with val: "<<mrav[i]<<endl;
        //prev.increment(i+1, mrav[i]);
        //cout<<"FINAL val at pos: "<<i+1<<": "<<prev.rangeGet(i+1, i+1)<<endl;
        prevIT.increment(i+1, mrav[i]);
        //return 0;
        //cout<<"get ans: "<<endl;cout.flush();
        //cout<<"Final val: "<<prevIT.get(i+1, i+1)<<endl;cout.flush();
        //cout<<"END";cout.flush();
    }
    wow[1] = prevIT;
    //return 0;
    //DEBUG
    //cout<<"pos1: "<<prevIT.get(1, 1)<<endl;
    //cout<<"sum 1 to 3: "<<prevIT.get(1, 2)<<endl;
    //DEBUG
    //cout<<"Hi";cout.flush();

    for(int i = 0; i < N-1; ++i)
    {
        int P, X, Y, V, Z, T, L, R, k, l;
        cin >> P >> X >> Y >> V >> Z >> T;

        L = ((X + S) % M) + 1; R = ((Y + S) % M) + 1;
        k = ((Z + S) % M) + 1; l = ((T + S) % M) + 1;
        secondIT = wow[P];
        //cout<<"S is: "<<S<<endl;
        for(int j = L; j <= R; ++j)
        {
            secondIT.increment(j, V);
        }
        wow[i+2] = secondIT;
        S = secondIT.get(k, l);
        cout<<S<<'\n';
        prevIT = secondIT;
        //cout<<"S: "<<S<<" L: "<<L<<" R: "<<R<<'\n';
        //cout<<"new MRAV:\n";
        for(int i = 0; i < M; ++i)
        {
            //cout<<prevIT.get(i+1, i+1)<<" ";
        }
        //cout<<endl;
    }
    //cout<<"first: "<<prevIT.get(3, 3);
   // cout << "Hello world!" << endl;
    return 0;
}
/*
4 4
3 6 7 5
1 2 3 1 0 1
2 1 2 6 2 2
1 0 2 8 0 3
*/
