class LazySegmentTree():

    __slots__ = ["n","num","merge","merge_unit","operate","merge_operate","operate_unit","data","lazy","count"]

    def __init__(self,n,init,merge,merge_unit,operate,merge_operate,operate_unit):
        self.merge=merge
        self.merge_unit=merge_unit
        self.operate=operate
        self.merge_operate=merge_operate
        self.operate_unit=operate_unit

        self.n=(n-1).bit_length()
        self.num = 1<<self.n
        self.data=[merge_unit for i in range(1<<(self.n+1))]
        self.lazy=[operate_unit for i in range(1<<(self.n+1))]
        if init:
            for i in range(n):
                self.data[2**self.n+i]=init[i]
            for i in range(2**self.n-1,0,-1):
                self.data[i]=self.merge(self.data[2*i],self.data[2*i+1])

    def update(self,l,r,x):
        l+=1<<self.n
        r+=1<<self.n
        l0=l//(l&-l)
        r0=r//(r&-r)-1

        i = l0
        m=i.bit_length()-1
        for bit in range(m,0,-1):
            v=i>>bit
            self.data[v] = self.operate(self.data[v],self.lazy[v])
            self.lazy[v<<1]=self.merge_operate(self.lazy[v<<1],self.lazy[v])
            self.lazy[(v<<1)+1]=self.merge_operate(self.lazy[(v<<1)+1],self.lazy[v])
            self.lazy[v]=self.operate_unit

        i = r0
        m=i.bit_length()-1
        for bit in range(m,0,-1):
            v=i>>bit
            self.data[v] = self.operate(self.data[v],self.lazy[v])
            self.lazy[v<<1]=self.merge_operate(self.lazy[v<<1],self.lazy[v])
            self.lazy[(v<<1)+1]=self.merge_operate(self.lazy[(v<<1)+1],self.lazy[v])
            self.lazy[v]=self.operate_unit


        while l<r:
            if l&1:
                self.lazy[l]=self.merge_operate(self.lazy[l],x)
                l+=1
            if r&1:
                self.lazy[r-1]=self.merge_operate(self.lazy[r-1],x)
            l>>=1
            r>>=1

        while l0:
            l0>>=1
            self.data[l0] = self.merge(self.operate(self.data[l0<<1],self.lazy[l0<<1]),self.operate(self.data[(l0<<1)+1],self.lazy[(l0<<1)+1]))

        while r0:
            r0>>=1
            self.data[r0] = self.merge(self.operate(self.data[r0<<1],self.lazy[r0<<1]),self.operate(self.data[(r0<<1)+1],self.lazy[(r0<<1)+1]))

    def query(self,l,r):
        l+=1<<self.n
        r+=1<<self.n
        l0=l//(l&-l)
        r0=r//(r&-r)-1
        i = l0
        m=i.bit_length()-1
        for bit in range(m,0,-1):
            v=i>>bit
            self.data[v] = self.operate(self.data[v],self.lazy[v])
            self.lazy[v<<1]=self.merge_operate(self.lazy[v<<1],self.lazy[v])
            self.lazy[(v<<1)+1]=self.merge_operate(self.lazy[(v<<1)+1],self.lazy[v])
            self.lazy[v]=self.operate_unit

        i = r0
        m=i.bit_length()-1
        for bit in range(m,0,-1):
            v=i>>bit
            self.data[v] = self.operate(self.data[v],self.lazy[v])
            self.lazy[v<<1]=self.merge_operate(self.lazy[v<<1],self.lazy[v])
            self.lazy[(v<<1)+1]=self.merge_operate(self.lazy[(v<<1)+1],self.lazy[v])
            self.lazy[v]=self.operate_unit

        res=self.merge_unit
        while l<r:
            if l&1:
                res = self.merge(res,self.operate(self.data[l],self.lazy[l]))
                l+=1
            if r&1:
                res = self.merge(res,self.operate(self.data[r-1],self.lazy[r-1]))
            l>>=1
            r>>=1
        return res>>32

import sys

input = sys.stdin.buffer.readline

mod = 998244353
mask = 2**32 - 1

def merge(x,y):
    s = ((x>>32) + (y>>32)) % mod
    num = (x&mask) + (y&mask)
    return (s<<32) + num

merge_unit = 0

def operate(x,ope):
    s,num = x>>32,x&mask
    b,c = ope>>32,ope&mask
    s = (b*s + c*num) % mod
    return (s<<32)+num

def merge_operate(x,y):
    b1,c1 = x>>32,x&mask
    b2,c2 = y>>32,y&mask
    return (((b1*b2)%mod)<<32)+((b2*c1+c2)%mod)

operate_unit = 1<<32

N,Q = map(int,input().split())
a = list(map(int,input().split()))
a = [(a[i]<<32)+1 for i in range(N)]

LST = LazySegmentTree(N,a,merge,merge_unit,operate,merge_operate,operate_unit)

for _ in range(Q):
    query = list(map(int,input().split()))
    if query[0] == 0:
        gomi,l,r,b,c = query
        LST.update(l,r,(b<<32)+c)
    else:
        gomi,l,r = query
        print(LST.query(l,r))

Measured memory_bytes: 179756