#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } #include using mint = atcoder::modint998244353; int main() { int n, q; cin >> n >> q; auto a = vec(uns, n); for (auto &e : a) cin >> e; sort(begin(a), end(a)); auto acc = vec(uns, n + 1); acc[0] = 1; for (int i = 0; i < n; ++i) { acc[i + 1] = acc[i] * a[i]; } auto dp = vec(uns, n + 1, n + 1); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= n; ++j) { dp[i][j] = (a[n - i] - 1) * dp[i - 1][j]; if (0 < j) { dp[i][j] += dp[i - 1][j - 1]; } } } while (q--) { int l, r, p; cin >> l >> r >> p; int ans = 0; for (int i = l; i <= r; ++i) { int d = n - distance(begin(a), lower_bound(begin(a), end(a), i)); ans ^= (acc[n - d] * dp[d][p]).val(); } cout << mint(ans).val() << endl; } }