mod = 998244353 class BIT: def __init__(self, n): self.n = n self.lst = [0 for _ in range(n + 1)] def add(self, p, x): while True: if p > self.n: break self.lst[p] += x self.lst[p] %= 998244353 p += (p & -p) def sum(self, p): res = 0 while True: if p <= 0: break res += self.lst[p] res %= 998244353 p -= (p & -p) return res def get(self, p): return (self.sum(p) - self.sum(p - 1)) % 998244353 N, M, K, Q = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): A[i] -= 1 inv_m = pow(M - 1, mod - 2, mod) pow_m = [1] for i in range(N): add_res = (pow_m[-1] * M) % mod pow_m.append(add_res) bit1 = BIT(N) bit2 = BIT(N) for i in range(N): bit1.add(i + 1, (pow(M, K - i, mod) * A[i]) % mod) bit2.add(i + 1, A[i]) for i in range(Q): t, l, r = map(int, input().split()) if t == 1: # do nothing l -= 1 r -= 1 ans = (r - l + 1) prd1 = bit1.sum(r + 1) - bit1.sum(l) prd1 = (prd1 * pow_m[l]) % mod prd2 = bit2.sum(r + 1) - bit2.sum(l) sums = (prd1 - prd2) % mod sums = (sums * inv_m) % mod ans = (ans + sums) % mod print(ans) else: l -= 1 r -= 1 now_bit1 = bit1.get(l + 1) now_bit2 = bit2.get(l + 1) bit1.add(l + 1, (-now_bit1 + pow(M, K - l, mod) * r) % mod) bit2.add(l + 1, (-now_bit2 + r) % mod)