#include #define int long long #define mod 998244353 using namespace std; int n, q; int p[5010]; int mul[5010][5010], inv[5010][5010]; signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } mul[0][0] = 1; inv[0][0] = 1; for (int i = 1; i <= n; i++) { memcpy(mul[i], mul[i - 1], sizeof(mul[i])); memcpy(inv[i], inv[i - 1], sizeof(inv[i])); for (int j = n; j >= 1; j--) { mul[i][j] += p[i] * mul[i][j - 1]; while (mul[i][j] < 0) { mul[i][j] += mod; } mul[i][j] %= mod; } for (int j = 0; j <= n - 1; j++) { inv[i][j + 1] -= p[i] * inv[i][j]; while (inv[i][j + 1] < 0) { inv[i][j + 1] += mod; } inv[i][j + 1] %= mod; } } cin >> q; while (q--) { int a, b, k; cin >> a >> b >> k; int ans = 0; for (int i = 0; i <= k; i++) { ans += mul[b][i] * inv[a - 1][k - i]; ans %= mod; } cout << ans << '\n'; } return 0; }