#include using namespace std; #include using namespace atcoder; istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); } istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } template istream &operator>>(istream &is, static_modint &a) { long long v; is >> v; a = v; return is; } template istream &operator>>(istream &is, dynamic_modint &a) { long long v; is >> v; a = v; return is; } template ostream &operator<<(ostream &os, const static_modint &a) { return os << a.val(); } template ostream &operator<<(ostream &os, const dynamic_modint &a) { return os << a.val(); } #define rep_(i, a_, b_, a, b, ...) for (int i = (a), lim##i = (b); i < lim##i; ++i) #define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define drep_(i, a_, b_, a, b, ...) for (int i = (a)-1, lim##i = (b); i >= lim##i; --i) #define drep(i, ...) drep_(i, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, 0) using ll = long long; template istream &operator>>(istream &is, vector &v) { for (auto &e : v) is >> e; return is; } template ostream &operator<<(ostream &os, const vector &v) { for (auto &e : v) os << e << ' '; return os; } struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; using mint = modint998244353; int main(){ // FILE *out = freopen("out1.txt", "w", stdout); int N; cin >> N; vector P(N); rep(i,N) cin >> P[i]; // func[B][X] := 1以上B以下の整数からX個選び、積の総和 vector> func(N+1, vector(N+1, 0)); rep(x,N+1){ if(x==0) continue; rep(b,N){ if(x==1){ func[b+1][1] = func[b][1] + P[b]; } else{ func[b+1][x] = func[b][x] + P[b]*func[b][x-1]; } } } /* rep(i,N+1){ rep(j,N+1){ cout << func[i][j] << (j==N?'\n':' '); } } */ int Q; cin >> Q; while(Q--){ int A, B, X; cin >> A >> B >> X; vector Vec_A_B_n(B+1, 1), Vec_1_A_1_n(B+1, 1), Vec_1_B_n(B+1, 1); for(int i=0;i<=B;i++){ Vec_1_A_1_n[i] = func[A-1][i]; Vec_1_B_n[i] = func[B][i]; } for(int i=1;i<=B;i++){ Vec_A_B_n[i] = Vec_1_B_n[i]; for(int j=0;j