#include using LL = long long; const int N = 5e3 + 7; const int MOD = 998244353; int a[N], f[N][N], g[N][N], n, m; int main() { scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); f[0][0] = g[0][0] = 1; for(int i = 1; i <= n; ++i) { f[i][0] = g[i][0] = 1; for(int j = n; j >= 1; --j) f[i][j] = (f[i - 1][j] + 1LL * a[i] * f[i - 1][j - 1]) % MOD; for(int j = 0; j < n; ++j) g[i][j + 1] = (g[i - 1][j + 1] - 1LL * a[i] * g[i][j]) % MOD; } scanf("%d", &m); while(m--) { int ans = 0, l, r, k; scanf("%d%d%d", &l, &r, &k); for(int i = 0; i <= k; ++i) ans = (ans + 1LL * f[r][i] * g[l - 1][k - i]) % MOD; printf("%d\n", (ans + MOD) % MOD); } return 0; }