#include <iostream>
using namespace std;
    int n, m;
struct node {
    long long sum, hills, perhill;
    int actualHills;
    node *right;
    node *left;
    long long getSum() {
        return sum + actualHills * perhill;
    }
    void updateSum() {
        sum = ((right == NULL) ? 0 : (right->getSum())) + ((left==NULL) ? 0 : left->getSum());
    }
} *roots[1 << 20];

long long hills[1 << 20];
int taken;

node* buildTree(int count) {
    if (count == 0) return NULL;
    node* r = new node;
    if (count == 1 && taken < n) {
        r->perhill = hills[taken++];
        r->actualHills = 1;
    } else {
        r->actualHills = 0;
    }
    r->hills = count;
    r->left = buildTree(count / 2);
    r->right = buildTree(count / 2);
    if (count > 1) {
        r->actualHills = r->left->actualHills + r->right->actualHills;
    }
    r->updateSum();
    return r;
}

node* newCity(node* old, int l, int r, int v) {
    node *res = new node;
    res->hills = old->hills;
    res->left = old->left;
    res->right = old->right;
    res->actualHills = old->actualHills;
    if (l == 0 && r == old->hills) {
        res->perhill = old->perhill + v;
        res->updateSum();
        return res;
    }
    if (r <= old->hills/2) {
        res->left = newCity(old->left, l, r, v);
        res->updateSum();
        return res;
    }
    if (l >= old->hills/2){
        res->right = newCity(old->right, l - old->hills/2, r - old->hills/2, v);
        res->updateSum();
        return res;
    }
    res->left = newCity(old->left, l, old->hills/2, v);
    res->right = newCity(old->right, 0, r - old->hills/2, v);
    res->updateSum();
    return res;
}

int query(node* city, int l, int r) {
    //cout << city->hills << ' ' << city->sum << ' ' << city->perhill << endl;
    //cout << l << ' ' << r << endl;
    //cout << city->sum << ' ' << city->hills << ' ' << city->perhill << ' ' << city->getSum()
    //     << endl;
    //if (city->hills > 1) {
    //    query(city->left, l, r);
    //    query(city->right, l, r);
    //}
    if (city->hills == 1) return city->getSum();
    if (l == 0 && city->hills == r) {
        return city->getSum();
    }
    if (r <= city->hills/2) {
        return query(city->left, l, r) + city->perhill * (r - l);
    }
    if (l >= city->hills/2) {
        return query(city->right, l - city->hills/2, r - city->hills/2) + city->perhill * (r - l);
    }
    return query(city->left, l, city->hills/2) + query(city->right, 0, r - city->hills/2) + city->perhill*(r - l);
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> hills[i];
    }
    int count = 1;
    while (count < m) count <<= 1;
    roots[1] = buildTree(count);
    long long s = 0;
    for (int i = 2; i <= m; ++i) {
        int origin, ul, ur, v, ql, qr;
        cin >> origin >> ul >> ur >> v >> ql >> qr;
        ul = (ul + s) % m;
        ur = ((ur + s) % m) + 1;
        ql = (ql + s) % m;
        qr = ((qr + s) % m) + 1;
        if (ul >= ur) while(1);
        if (ql >= qr) while(1);
        roots[i] = newCity(roots[origin], ul, ur, v);
        //cout << ql << ' ' << qr << endl;
        //cout << ul << ' ' << ur << endl;
        s = query(roots[i], ql, qr);
        cout << s << '\n';
        //cin >> s;
    }
    return 0;
}
