#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long Int;

int n,m;
int a[100001];

///Static memory

struct Node
{
    Int sum;
    Int upd;
    int s1,s2;
};

const int MAXMEM=7000000;
Node Mem[MAXMEM+1];
int MemoryStack[MAXMEM+1];
int MSL=0;

void Clear(int k)
{
    Mem[k].sum=0;
    Mem[k].upd=0;
    Mem[k].s1=0;
    Mem[k].s2=0;
    
    return;
}

void InitMem()
{
    int i;
    
    Clear(0);
    
    for (i=1;i<=5000000;i++)
    {
        MemoryStack[i]=5000000-i+1;
    }
    MSL=5000000;
    
    return;
}

int AllocMem()
{
    MSL--;
    
    if (MSL<0)
    while(1);
    
    Clear(MemoryStack[MSL+1]);
    
    return MemoryStack[MSL+1];
}

struct PTree
{
    int roots[100001];
    int rootctr;
    int LEAFOFFSET;
    
    void Init(int n)
    {
        roots[1]=AllocMem();
        rootctr=1;
        
        ///cout<<"Root 1 allocated at "<<roots[1]<<" with leafoffset=";
        
        LEAFOFFSET=1;
        while(LEAFOFFSET<n)
        LEAFOFFSET*=2;
        LEAFOFFSET--;
        
        ///cout<<LEAFOFFSET<<endl;
        
        return;
    }
    
    void Refresh(int ver,int versz)
    {
        if (Mem[ver].upd!=0)
        {
            Mem[ver].sum+=(Int)versz*Mem[ver].upd;
            
            if (versz==1)
            {
                Mem[ver].upd=0;
                return;
            }
            
            if (Mem[ver].s1==0)
            {
                Mem[ver].s1=AllocMem();
            }
            Mem[ Mem[ver].s1 ].upd+=Mem[ver].upd;
            
            if (Mem[ver].s2==0)
            {
                Mem[ver].s2=AllocMem();
            }
            Mem[ Mem[ver].s2 ].upd+=Mem[ver].upd;
            
            Mem[ver].upd=0;
        }
        
        return;
    }
    
    bool Intersect(int L,int R,int l,int r)
    {
        if (L>r || R<l)
        return false;
        else
        return true;
    }
    
    void Upd(int ver,int L,int R,int ind,int v)
    {
        ///cout<<"Entering ["<<ver<<"] at "<<L<<"~"<<R<<" looking for "<<ind<<endl;
        //Refresh(ver,R-L+1);
        
        //if (L>r || R<l)
        //return; //must not come here for memory reduction
        if (L==R)
        {
            Mem[ver].sum+=(Int)v;
            ///cout<<"Found it, increasing by "<<v<<endl;
            ///cout<<"New sum="<<Mem[ver].sum<<endl;
            
            //Refresh(ver) - memory reduction, as it's not necessary
            
            return;
        }
        else
        {
            ///cout<<"Cutting in kids"<<endl;
            if ( Intersect(L,(L+R)/2,ind,ind) )
            {
                if (Mem[ver].s1==0)
                {
                    Mem[ver].s1=AllocMem();
                }
                
                Upd(Mem[ver].s1,L,(L+R)/2,ind,v);
            }
            
            if ( Intersect((L+R)/2+1,R,ind,ind) )
            {
                if (Mem[ver].s2==0)
                {
                    Mem[ver].s2=AllocMem();
                }
                
                Upd(Mem[ver].s2,(L+R)/2+1,R,ind,v);
            }
            
            ///cout<<"Coming back at "<<ver<<" we get a sum of ";
            Mem[ver].sum=Mem[ Mem[ver].s1 ].sum+Mem[ Mem[ver].s2 ].sum;
            ///cout<<Mem[ver].sum<<endl;
        }
    }
    
    void Update(int root,int ind,int val)
    {
        ///cout<<"From root "<<root<<" we are updating "<<ind<<" with "<<val<<endl;
        Upd(roots[root],1,LEAFOFFSET+1,ind,val);
    }
    
    ///
    
    Int Q(int ver,int L,int R,int l,int r)
    {
        if (ver==0) //Memory reduction
        return 0;
        
        Refresh(ver,R-L+1);
        
        if (L>l || R<r)
        return 0; //must not come here for memory reduction
        else if (L>=l && R<=r)
        {
            return Mem[ver].sum;
        }
        else
        {
            Int sum=0;
            
            if ( Intersect(L,(L+R)/2,l,r) )
            {
                /*
                if (Mem[ver].s1==0)
                {
                    Mem[ver].s1=AllocMem();
                }
                */
                sum+=Q(Mem[ver].s1,L,(L+R)/2,l,r);
            }
            
            if ( Intersect((L+R)/2+1,R,l,r) )
            {
                /*
                if (Mem[ver].s2==0)
                {
                    Mem[ver].s2=AllocMem();
                }
                */
                sum+=Q(Mem[ver].s2,(L+R)/2+1,R,l,r);
            }
            
            return sum;
        }
    }
    
    Int Query(int root,int L,int R)
    {
        return Q(roots[root],1,LEAFOFFSET+1,L,R);
    }
    
    ///
    
    void Print(int k)
    {
        ///cout<<Mem[k].sum<<";"<<Mem[k].upd<<";"<<Mem[k].s1<<";"<<Mem[k].s2<<endl;
        return;
    }
    
    void NewRefresh(int ver,int versz,int copier)
    {
        if (Mem[ver].upd!=0)
        {
            ///cout<<"Refreshing "<<ver<<" with "<<Mem[ver].upd<<endl;
            
            Mem[ver].sum+=(Int)versz*Mem[ver].upd;
            
            if (versz==1)
            {
                Mem[ver].upd=0;
                return;
            }
            
            /*
            if (Mem[ver].s1==0)
            {
                Mem[ver].s1=AllocMem();
                
                if (Mem[copier].s1!=0)
                Mem[ Mem[ver].s1 ]=Mem[ Mem[copier].s1 ];
            }
            */
            ///cout<<"Adding update to "<<Mem[ver].s1<<endl;
            Mem[ Mem[ver].s1 ].upd+=Mem[ver].upd;
            ///cout<<"Total of "<<Mem[ Mem[ver].s1 ].upd<<endl;
            
            /*
            if (Mem[ver].s2==0)
            {
                Mem[ver].s2=AllocMem();
                
                if (Mem[copier].s2!=0)
                Mem[ Mem[ver].s2 ]=Mem[ Mem[copier].s2 ];
            }
            */
            ///cout<<"Adding update to "<<Mem[ver].s2<<endl;
            Mem[ Mem[ver].s2 ].upd+=Mem[ver].upd;
            ///cout<<"Total of "<<Mem[ Mem[ver].s2 ].upd<<endl;
            
            Mem[ver].upd=0;
        }
        
        return;
    }
    
    void UPD(int ver,int L,int R,int l,int r,int v,int copier)
    {
        if (L!=R)
        {
            ///cout<<"New left kid of "<<ver;
            
            Mem[ver].s1=AllocMem();
            
            ///cout<<" at "<<Mem[ver].s1<<endl;
            ///cout<<"Copier was "<<copier<<endl;
            
            if (Mem[copier].s1!=0)
            Mem[ Mem[ver].s1 ]=Mem[ Mem[copier].s1 ];
            
            ///cout<<"The kid looks as:"<<endl;
            ///Print(Mem[ver].s1);
        }
        
        if (L!=R)
        {
            ///cout<<"New right kid of "<<ver;
            
            Mem[ver].s2=AllocMem();
            
            ///cout<<" at "<<Mem[ver].s2<<endl;
            ///cout<<"Copier was "<<copier<<endl;
            
            if (Mem[copier].s2!=0)
            Mem[ Mem[ver].s2 ]=Mem[ Mem[copier].s2 ];
            
            ///cout<<"The kid looks as:"<<endl;
            ///Print(Mem[ver].s2);
        }
        
        NewRefresh(ver,R-L+1,copier);
        
        if (L>r || R<l)
        return; //must not come here for memory reduction
        else if (L>=l && R<=r)
        {
            Mem[ver].upd+=(Int)v;
            ///cout<<"Reached base "<<ver<<" and updating it with "<<v<<endl;
            
            
            NewRefresh(ver,R-L+1,copier);
            
            ///cout<<"New sum is ";
            ///cout<<Mem[ver].sum<<endl;
            
            return;
        }
        else
        {
            ///cout<<"Splitting kids "<<endl;
            
            if (Intersect(L,(L+R)/2,l,r))
            {
                UPD(Mem[ver].s1,L,(L+R)/2,l,r,v,Mem[copier].s1);
            }
            
            if (Intersect((L+R)/2+1,R,l,r))
            {
                UPD(Mem[ver].s2,(L+R)/2+1,R,l,r,v,Mem[copier].s2);
            }
            
            Mem[ver].sum=Mem[ Mem[ver].s1 ].sum+Mem[ Mem[ver].s2 ].sum;
            
            ///cout<<"Coming back at "<<ver<<" sum="<<Mem[ver].sum<<endl;
        }
        
        return;
    }
    
    void NewTreeUpdate(int root,int L,int R,int v)
    {
        rootctr++;
        roots[rootctr]=AllocMem();
        
        ///cout<<"Creating new root = "<<roots[rootctr]<<" being number "<<rootctr<<endl;
        
        Mem[ roots[rootctr] ]=Mem[ roots[root] ];
        
        ///cout<<"New info of new root = "<<endl;
        ///Print(roots[rootctr]);
        
        UPD(roots[rootctr],1,LEAFOFFSET+1,L,R,v,roots[root]);
        
        return;
    }
};

PTree Tree;

int main()
{
    //freopen("sample.txt","r",stdin);
    
    int i;
    Int S=0;
    int P,X,Y,V,Z,T;
    int pL,pR;
    int L,R;
    
    scanf("%d %d",&n,&m);
    
    InitMem();
    Tree.Init(m);
    
    for (i=1;i<=m;i++)
    {
        scanf("%d",&a[i]);
        
        Tree.Update(1,i,a[i]);
    }
    
    for (i=1;i<=n-1;i++)
    {
        scanf("%d %d %d %d %d %d",&P,&X,&Y,&V,&Z,&T);
        
        L=((X+S)%m)+1;
        R=((Y+S)%m)+1;
        pL=((Z+S)%m)+1;
        pR=((T+S)%m)+1;
        
        ///cout<<endl;
        ///cout<<"Query for increasing "<<L<<"~"<<R<<" with "<<V<<" initiated "<<endl;
        
        Tree.NewTreeUpdate(P,L,R,V);
        
        ///cout<<endl;
        ///cout<<"Wanting sum in "<<pL<<"~"<<pR<<" in last tree!"<<endl;
        
        S=Tree.Query(i+1,pL,pR);
        
        printf("%lld\n",S);
        
        S=S%(Int)m;
    }
    
    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
**/