import bisect import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) mod = 998244353 N, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() prod = [1] * (N + 1) for i, a in enumerate(A, 1): prod[i] = prod[i-1] * a % mod A.reverse() prod.reverse() """ dp[i,j]: i番目までみて、j個選んだ時の積の輪 """ dp = [[0] * (N + 1) for _ in range(N + 1)] dp[0][0] = 1 for i, a in enumerate(A, 1): for j in range(i): dp[i][j] += dp[i-1][j] * (a - 1) dp[i][j] %= mod dp[i][j+1] += dp[i-1][j] dp[i][j+1] %= mod for _ in range(Q): L, R, P = map(int, input().split()) res = 0 i = 0 for x in range(L, R+1)[::-1]: while i < N and A[i] >= x: i += 1 cnt = dp[i][P] * prod[i] % mod res ^= cnt print(res % mod)