#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];
node array[18 << 18];
int allocated;

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

node* buildTree(int count) {
    if (count == 0) return NULL;
    //node* r = new node;
    node *r = &array[allocated++];
    if (count == 1 && taken < m) {
        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) {
    while (old == NULL);
    //node *res = new node;
    node *res = &array[allocated++];
    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;
}

void print(node *city) {
    cout << city->sum << ' ' << city->hills << ' ' << city->perhill << ' ' << city->getSum()
         << endl;
    if (city->hills > 1) {
        print(city->left);
        print(city->right);
    }
}

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);
    //}
    while (city == NULL);
    if (city->actualHills == 0) return 0;
    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.tie(0); ios::sync_with_stdio(false);
    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);
        //cout << "---------------------------\n" <<endl;
        //print(roots[1]);
        //cout << "---------------------------\n";
    long long s = 0;
    for (int i = 2; i <= n; ++i) {
        if (allocated > (17 << 18)) while(1);
        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;
        //cout << ul << ur<< ql<<qr<<endl;
        roots[i] = newCity(roots[origin], ul, ur, v);
        //cout << "---------------------------\n";
        //print(roots[i]);
        //cout << "---------------------------\n";
        //cout << ql << ' ' << qr << endl;
        //cout << ul << ' ' << ur << endl;
        s = query(roots[i], ql, qr);
        cout << s << '\n';
        //cin >> s;
    }
    return 0;
}
