#include #include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) const u32 MOD = 998244353; struct F{ u32 a=1, b=0; u32 operator()(u32 x){ return ((u64)a*x + b) % MOD; } F operator+(F r){ return { (u32)(((u64)a*r.a) % MOD), (u32)(((u64)b*r.a+r.b) % MOD) }; } }; struct Segtree{ int N, logN; vector> A; Segtree(const vector& a){ int n = a.size(); N = 1; logN = 0; while(N < n){ N *= 2; logN++; } A.assign(logN+1, vector(N, F())); rep(i,n) A[0][i] = a[i]; rep(d,logN) rep(i,N) A[d+1][i] = A[d][i] + A[d][i^(1<> N >> Q; vector A(N); rep(i,N) cin >> A[i].a >> A[i].b; Segtree rq(A); rep(i,Q){ int l,r,p; u32 x; cin >> l >> r >> p >> x; u32 ans = rq.prod(l,r,p)(x); cout << ans << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;