#include <bits/stdc++.h>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL,LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQGI; //大きい順
typedef priority_queue<int, VI, greater<int>> PQLI;
typedef priority_queue<PII> PQGP;
typedef priority_queue<PII, VPII, greater<PII>> PQLP;
//priority_queue<T,vector<T>,decltype(f)> pq{f};

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EB emplace_back
#define EF emplace_front
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).rbegin(), (c).rend())
#define LB lower_bound
#define UB upper_bound
#define NEXP next_permutation
#define FI first
#define SE second
#define Vmin(a) *min_element((a).begin(),(a).end())
#define Vmax(a) *max_element((a).begin(),(a).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORR(i,a,b) for(int i = (b-1);i>=(a);i--)
#define REPR(i,n) FORR(i,0,n)
#define CFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define CREP(i,n)  CFOR(i,0,n)
#define CFORR(i,a,b) for(int i = (b);i>=(a);i--)
#define CREPR(i,n) CFORR(i,0,n)
#define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define BREP(bit,n) BFOR(bit,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = INT_MAX/2;
const LL LINF = LLONG_MAX/3;
const int RINF = INT_MIN/2;
const LL RLINF = LLONG_MIN/3;
const LL MOD = 1e9+7;
const LL MODD = 998244353;
const int MAX = 510000;

inline bool Eq(double a, double b) { return fabs(b - a) < EPS; }

//other
//-------------------------------------------
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define COUT(x) cout << (x) << endl
#define COUT2(x,y) cout << (x) << " " << (y) << endl
#define COUT3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define PR(x) cout << (x)
#define ENDL cout << endl
#define SPACE cout << " "
#define BC(x) __builtin_popcountll(x)

VI dx = {1,0,-1,0,1,1,-1,-1};
VI dy = {0,1,0,-1,1,-1,1,-1};

LL Gcd(LL a, LL b) {return __gcd(a,b);}
LL Lcm(LL a, LL b) {return a/Gcd(a,b)*b;}

LL ModPow(LL A, LL N, LL M=MOD){
  LL res = 1;
  while(N>0){
    if(N&1) res = res * A % M;
    A = A * A % M;
    N >>= 1;
  }
  return res;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
using mint = ModInt< MODD >;
using VM = vector<mint>;
using VVM = vector<VM>;

template<typename M, typename OM = M>
struct LazySegTree{
  using F = function<M(M, M)>;
  using G = function<M(M, OM)>;
  using H = function<OM(OM, OM)>;

  int n, defn, height;
  vector<M> node;
  vector<OM> lazy;
  const F f;
  const G g;
  const H h;
  const M m;
  const OM om;

  LazySegTree(int _n, const F f, const G g, const H h, const M m, const OM om): f(f), g(g), h(h), m(m), om(om){
    n = 1;
    defn = _n;
    height = 1;
    while(n<defn) n<<=1, height++;
    node.assign(2*n, m);
    lazy.assign(2*n, om);
  }

  void set(int k, const M &x){
    node.at(k + n) = x;
  }
  void build(){
    REPR(k, n){
      node.at(k) = f(node.at(2*k), node.at(2*k+1));
    }
  }

  void propagate(int k){ node.at(k) = f(node.at(2*k), node.at(2*k + 1));}
  void all_apply(int k, OM x){
    node.at(k) = g(node.at(k), x);
    if(k < n) lazy.at(k) = h(lazy.at(k), x);
  }
  void push(int k){
    all_apply(2*k, lazy.at(k));
    all_apply(2*k + 1, lazy.at(k));
    lazy.at(k) = om;
  }

  void change(int k, M &x){
    k += n;
    for(int i = height; i>=1; --i) push(k >> i);
    node.at(k) = x;
    for(int i=1; i <= height; i++) propagate(k >> i);
  }
  void update(int k, const OM &x){
    k += n;
    for(int i = height; i>=1; --i) push(k >> i);
    node.at(k) = g(node.at(k), x);
    for(int i=1; i <= height; i++) propagate(k >> i);
  }

  void update(int l, int r, const OM &x){
    if(l == r) return;
    l += n; r += n;

    for(int i = height; i>=1; --i){
      if(((l>>i)<<i) != l) push(l >> i);
      if(((r>>i)<<i) != r) push((r-1) >> i);
    }

    {
      int l2 = l, r2 = r;
      while(l2 < r2){
        if(l2&1) all_apply(l2++, x);
        if(r2&1) all_apply(--r2, x);
        l2 >>= 1;
        r2 >>= 1;
      }
    }

    for(int i = 0; i <= height; ++i){
      if(((l>>i)<<i) != l) propagate(l >> i);
      if(((r>>i)<<i) != r) propagate((r-1) >> i);
    }
  }

  M at(int k){
    k += n;
    for(int i = height; i>=1; --i) push(k >> i);
    return node.at(k);
  }

  M query(int l, int r){
    if(l == r) return m;
    l += n; r += n;

    for(int i = height; i>=1; --i){
      if(((l>>i)<<i) != l) push(l >> i);
      if(((r>>i)<<i) != r) push(r >> i);
    }

    M sl = m, sr = m;
    while(l < r){
      if(l&1) sl = f(sl, node.at(l++));
      if(r&1) sr = f(node.at(--r), sr);
      l >>= 1;
      r >>= 1;
    }
    return f(sl, sr);
  }

  M all_query() { return node.at(1); }

  template<typename C>
  int max_right(int l, C &check){
    if(l == defn) return defn;
    l += n;
    for(int i = height; i>=1; --i) push(l >> i);
    M sm = m;
    do{
      while(l%2 == 0) l >>= 1;
      if(!check(f(sm, node.at(l)))){
        while(l < n){
          push(l);
          l *= 2;
          if(check(f(sm, node.at(l)))){
            sm = f(sm, node.at(l));
            l++;
          }
        }
        return l - n;
      }
      sm = f(sm, node.at(l));
      l++;
    }while((l&-l) != l);
    return defn;
  }

  template<typename C>
  int max_left(int r, C &check){
    if(r == 0) return 0;
    r += n;
    for(int i = height; i>=1; --i) push((r-1) >> i);
    M sm = m;
    do{
      while(r>1 && (r%2)) r >>= 1;
      if(!check(f(node.at(r), sm))){
        while(r < n){
          push(r);
          r *= 2*r + 1;
          if(check(f(node.at(r), sm))){
            sm = f(node.at(r), sm);
            r--;
          }
        }
        return r + 1 - n;
      }
      sm = f(node.at(r), sm);
    }while((r&-r) != r);
    return 0;
  }
};

int main() {

  // cin.tie(0);
  // ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, Q;
  cin >> N >> Q;

  using PM = pair<mint,mint>;

  LazySegTree<PM> seg(
    N,
    [](PM a, PM b) {return MP(a.FI+b.FI,a.SE+b.SE);},
    [](PM a, PM b) {return MP(a.FI*b.FI+a.SE*b.SE,a.SE);},
    [](PM a, PM b) {return MP(a.FI*b.FI,a.SE*b.FI+b.SE);},
    {0, 0},
    {1, 0}
  );

  REP(i,N){
    mint a;
    cin >> a;
    seg.set(i,{a,1});
  }

  seg.build();

  REP(q,Q){
    int t;
    cin >> t;
    if(t == 0){
      int l,r;
      mint b,c;
      cin >> l >> r >> b >> c;
      seg.update(l,r,{b,c});
    }else{
      int l,r;
      cin >> l >> r;
      PM res = seg.query(l, r);
      COUT(res.FI);
    }
  }

  return 0;
}


Measured memory_bytes: 19524