#include <cstdio>
#include <algorithm>
using namespace std;
int m,n,p,x,y,z,v,t,l,r,I,J,s,val,poz,i,sum;
int a[200005];
void compute()
{
    l=((x+s)%m)+1;
    r=((y+s)%m)+1;
    I=((z+s)%m)+1;
    J=((t+s)%m)+1;
}
void update1(int nod,int st, int dr)
{
    int m;
    if(st>=poz && dr<=poz)
    {
        a[nod]=val;
        return;
    }
    m=(st+dr)/2;
    if(m>=poz)
    {

        update1(nod*2,st,m);
    }
    else
    {
        update1(nod*2+1,m+1,dr);
    }
    a[nod]=a[nod*2]+a[nod*2+1];
}
void update2(int nod,int st, int dr)
{
    int m;
    if(st>=poz && dr<=poz)
    {
        a[nod]+=v;
        return;
    }
    m=(st+dr)/2;
    if(m>=poz)
    {

        update2(nod*2,st,m);
    }
    else
    {
        update2(nod*2+1,m+1,dr);
    }
    a[nod]=a[nod*2]+a[nod*2+1];
}
void query(int nod, int st, int dr)
{
    int m;
    if(st>=I && dr<=J)
    {
        sum+=a[nod];
        return;
    }
    m=(st+dr)/2;
    if(I<=m) query(2*nod,st,m);
    if(m<J) query(2*nod+1,m+1,dr);
}
int main()
{
    /*freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);*/
    scanf("%d %d",&n,&m);

    for(i=1; i<=m; i++)
    {
        scanf("%d ",&val);
        poz=i;
        update1(1,1,n);
    }
    s=0;
    for(i=1; i<n; i++)
    {
        scanf("%d %d %d %d %d %d",&p,&x,&y,&v,&z,&t);
        compute();
        for(int j=l; j<=r; j++)
        {
            poz=j;
            update2(1,1,n);
        }
    sum=0;
    query(1,1,n);
    printf("%d\n",sum);
     s=sum;
    }
    return 0;
}

