MOD = 998244353 def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 P = list(map(int, input[ptr:ptr+N])) ptr += N Q = int(input[ptr]) ptr += 1 for _ in range(Q): A = int(input[ptr]) B = int(input[ptr+1]) K = int(input[ptr+2]) ptr +=3 A -= 1 # Convert to 0-based index B -= 1 sub = P[A:B+1] L = B - A + 1 if K > L: print(0) continue dp = [0] * (K + 1) dp[0] = 1 current_max = 0 for num in sub: current_max = min(current_max + 1, K) for k in range(current_max, 0, -1): dp[k] = (dp[k] + dp[k-1] * num) % MOD print(dp[K] % MOD) if __name__ == "__main__": main()