#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
typedef long long lld;

struct IntervalTree
{
    struct Element
    {
        lld l, r;
        lld sum;
        lld elcnt;
        
        bool needupd;
        lld updval;
    };
    
    Element IT[700002], empt;
    lld lbeg, lend;
    
    Element Merge (Element a, Element b)
    {
        Element ret;
        
        ret.l = a.l; ret.r = b.r;
        ret.elcnt = a.elcnt+b.elcnt;
        ret.sum = a.sum + b.sum;
        
        ret.needupd = (a.updval || b.updval);
        ret.updval = a.updval + b.updval;
        
        return ret;
    }
    bool Leaf(lld ind)
    {
        return (ind >= lbeg);
    }
    
    void Initialize(lld arr[], lld n)
    {
        lld i;
        
        lbeg = 1;
        while (lbeg < n)
        {
            lbeg *= 2;
        }
        lend = lbeg+n-1;
        
        empt.l = n;
        empt.r = n;
        empt.sum = 0;
        empt.needupd = false;
        empt.updval = 0;
        empt.elcnt = 0;
        
        for (i=lend+1; i<700002; i++)
        {
            IT[i] = empt;
        }
        for (i=lbeg; i<=lend; i++)
        {
            IT[i].l = IT[i].r = i-lbeg+1;
            IT[i].sum = arr[i-lbeg+1];
            IT[i].needupd = false;
            IT[i].updval = 0;
            IT[i].elcnt = 1;
        }
        for (i=lbeg-1; i>=1; i--)
        {
            IT[i] = Merge(IT[i*2], IT[i*2+1]);
        }
    }
    
    void LazyLogging(lld ind)
    {
        if (ind > lend) return;
        
        if (!IT[ind].needupd) return;
        
        IT[ind].sum += (IT[ind].elcnt)*IT[ind].updval;
        
        
        if (!Leaf(ind))
        {
            IT[ind*2].needupd = true;
            IT[ind*2].updval += IT[ind].updval;
            
            IT[ind*2+1].needupd = true;
            IT[ind*2+1].updval += IT[ind].updval;
        }

        
        IT[ind].updval = 0;
        IT[ind].needupd = false;
    }
    
    lld QRY(lld ind, lld from, lld to)
    {
        if (ind > lend) return 0;
        
        LazyLogging(ind);
        
        if (IT[ind].r < from || to < IT[ind].l) return 0;
        
        if (from <= IT[ind].l && IT[ind].r <= to)
        {
            return IT[ind].sum;
        }
        
        lld v1 = QRY(ind*2, from, to), v2 = QRY(ind*2+1, from, to);
        
        if (!Leaf(ind))
        IT[ind] = Merge(IT[ind*2], IT[ind*2+1]);
        
        return v1+v2;
    }
    void UPD(lld ind, lld from, lld to, lld ad)
    {
        if (ind > lend) return;
        
        LazyLogging(ind);
        
        if (IT[ind].r < from || to < IT[ind].l) return;
        
        if (from <= IT[ind].l && IT[ind].r <= to)
        {
            lld sv = IT[ind].sum;
            IT[ind].sum += IT[ind].elcnt*ad;
            
            if (!Leaf(ind))
            {
                IT[ind*2].needupd = true;
                IT[ind*2].updval += ad;
                
                IT[ind*2+1].needupd = true;
                IT[ind*2+1].updval += ad;
            }
            
            return;
        }
        
        UPD(ind*2, from, to, ad);
        UPD(ind*2+1, from, to, ad);
        
        if (!Leaf(ind))
            IT[ind] = Merge(IT[ind*2], IT[ind*2+1]);
    }
    
    void Update (lld from, lld to, lld ad)
    {
        UPD(1, from, to, ad);
    }
    lld GetSum(lld from, lld to)
    {
        return QRY(1, from, to);
    }
};

struct QRY
{
    lld arr[7];
};

QRY ReadQRY()
{
    lld i;
    QRY ret;
    
    for (i=1; i<=6; i++)
    {
        scanf("%lld", &(ret.arr[i]));
    }
    
    return ret;
}

vector<QRY> qs;

IntervalTree magic;
lld arr[100002],n;
lld queries, q;
lld gett[2002][2002];

void BaseInput()
{
    lld i;
    
    scanf("%lld %lld", &queries, &n);
    for (i=1; i<=n; i++)
    {
        scanf("%lld", &arr[i]);
    }
}

lld MakeNew(lld ind, lld twin, lld l, lld r, lld v, lld pi, lld pj)
{
    lld i;
    lld ret=0;
    
    //cout<<"Ot "<<pi<<" do "<<pj<<"\n";
   // cout<<"pravq "<<ind<<" kato "<<twin<<"\n";
    
    for (i=1; i<=n; i++)
    {
        gett[ind][i] = gett[twin][i];
        
        //cout<<"Stoinostta mu shte e "<<gett[ind][i]<<" ako ne i dobavq nistho \n";
        
        if (l <= i && i <= r)
        {
            gett[ind][i] += v;
        }
        
        if (pi <= i && i <= pj)
        {
            ret += gett[ind][i];
        }
    }
    
    return ret;
}

int main ()
{
    //freopen("test.txt", "r", stdin);
    
    lld i, j;
    lld p, x, y, v, z, t;
    lld s=0;
    lld L, R, ans;
    bool bad = false;
    
    BaseInput();
    
    magic.Initialize(arr, n);
    //cout<<"yea, "<<n<<"\n";
    
    for (q=1; q<queries; q++)
    {
        qs.push_back(ReadQRY());
        
        if (qs.back().arr[1] != q)
        {
            bad = true;
        }
    }
    
    if (!bad)
    for (q=0; q<qs.size(); q++)
    {
        p = qs[q].arr[1];
        x = qs[q].arr[2];
        y = qs[q].arr[3];
        v = qs[q].arr[4];
        z = qs[q].arr[5];
        t = qs[q].arr[6];
        
        L = ((x+s)%n)+1; R = ((y+s)%n)+1;
        i = ((z+s)%n)+1; j = ((t+s)%n)+1;
        
        //cout<<L<<","<<R<<","<<i<<","<<j<<"\n";
        
        magic.Update(L, R, v);
        ans = magic.GetSum(i, j);
        
        printf("%lld\n", ans);
        
        s = ans;
    }
    
    
    else
    {
        if (n > 2000)
        {
            while (true)
            {
                
            }
        }
        
        for (i=1; i<=n; i++)
        {
            gett[1][i] = arr[i];
        }
        
        for (q=0; q<qs.size(); q++)
        {
            p = qs[q].arr[1];
            x = qs[q].arr[2];
            y = qs[q].arr[3];
            v = qs[q].arr[4];
            z = qs[q].arr[5];
            t = qs[q].arr[6];
            
            L = ((x+s)%n)+1; R = ((y+s)%n)+1;
            i = ((z+s)%n)+1; j = ((t+s)%n)+1;
            
            ans = MakeNew(q+2, p, L, R, v, i, j);
            
            printf("%lld\n", ans);
            
            s = ans;
        }
    }
    
}