#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define re register
#define in inline
#define pb(x) push_back(x)
#define F(i,a,b) for(re int i = a;i <= b;i++)
#define D(i,a,b) for(re int i = a;i >= b;i--)
const int N = 3e5+10,M = N<<2;
const ll inf = 1e17,mod = 998244353;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m;
ll a[N],b[N];
struct Tree{
ll sum[M],la1[M],la2[M],s1[M],s2[M];
void pushup(int p){
sum[p] = (sum[p<<1] + sum[p<<1|1]) % mod;
s1[p] = (s1[p<<1] + s1[p<<1|1]) % mod;
s2[p] = (s2[p<<1] + s2[p<<1|1]) % mod;
}
void update(int p,ll x,ll y,int l,int r){
(la1[p] += x) %= mod,(la2[p] += y) %= mod;
(sum[p] += (s1[p] * y % mod + s2[p] * x % mod + (ll)(r-l+1) * x * y % mod) % mod) %= mod;
(s1[p] += (ll)(r-l+1) * x % mod,s2[p] += (ll)(r-l+1) * y % mod) %= mod;
}
void pushdown(int p,int l,int r){
int mid = l + r >> 1;
update(p<<1,la1[p],la2[p],l,mid);
update(p<<1|1,la1[p],la2[p],mid+1,r);
la1[p] = la2[p] = 0;
}
void build(int p,int l,int r){
if(l == r)return sum[p] = (a[l] % mod * b[l]) % mod,s1[p] = a[l] % mod,s2[p] = b[l] % mod,void();
int mid = l + r >> 1;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
pushup(p);
}
void add(int p,int l,int r,int L,int R,ll z,bool f){
if(L <= l && r <= R){
if(f)update(p,z,0,l,r);
else update(p,0,z,l,r);
return;
}
pushdown(p,l,r);
int mid = l + r >> 1;
if(L <= mid)add(p<<1,l,mid,L,R,z,f);
if(R > mid)add(p<<1|1,mid+1,r,L,R,z,f);
pushup(p);
}
ll ask(int p,int l,int r,int L,int R){
if(L <= l && r <= R)return sum[p];
int mid = l + r >> 1;ll ans = 0;
pushdown(p,l,r);
if(L <= mid)(ans += ask(p<<1,l,mid,L,R)) %= mod;
if(R > mid)(ans += ask(p<<1|1,mid+1,r,L,R)) %= mod;
return ans;
}
}t;
int main(){
n = read();m = read();
F(i,1,n)a[i] = read();
F(i,1,n)b[i] = read();
t.build(1,1,n);
F(i,1,m){
int op = read(),l = read(),r = read();
if(op == 1)t.add(1,1,n,l,r,read(),1);
else if(op == 2)t.add(1,1,n,l,r,read(),0);
else printf("%lld\n",t.ask(1,1,n,l,r));
}
return cerr<<clock()<<"ms"<<endl,0;
}