#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } struct FPS: vector{ using vector::vector; FPS inv(int deg){ FPS ans(deg); ans[0] = mint(1)/(*this)[0]; for(int d = 1; d < deg; d<<=1){ vector f(2*d), g(2*d); for(int i = 0; i < min(2*d, (int)this->size()); i++) f[i] = (*this)[i]; for(int i = 0; i < d; i++) g[i] = ans[i]; f = atcoder::convolution(g, atcoder::convolution(g, f)); for(int i = d; i < min(2*d, deg); i++) ans[i] = -f[i]; } return ans; } void shrink() { while (this->size() && this->back() == mint(0)) this->pop_back(); } FPS& operator*=(const FPS &r){ if(this->empty() || r.empty()){ this->clear(); return *this; } auto ret = atcoder::convolution(*this, r); return *this = FPS(ret.begin(), ret.end()); } FPS& operator+=(const FPS &r){ if(this->size() < r.size()) this->resize(r.size()); for(int i = 0; i < (int)r.size(); i++) (*this)[i] += r[i]; return *this; } FPS& operator-=(const FPS &r){ if(this->size() < r.size()) this->resize(r.size()); for(int i = 0; i < (int)r.size(); i++) (*this)[i] -= r[i]; return *this; } FPS operator*(const FPS &r) const { return FPS(*this) *= r; } FPS operator+(const FPS &r) const { return FPS(*this) += r; } FPS operator-(const FPS &r) const { return FPS(*this) -= r; } FPS mod_deg(int deg){ FPS ret(deg); for(int i = 0; i < min(deg, (int)this->size()); i++) ret[i] = (*this)[i]; return ret; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector p(n); for(int i = 0; i < n; i++) cin >> p[i]; vector from_left(n+1); vector from_right(n+1); from_left[0] = {mint(1)}; from_right[n] = {mint(1)}; for(int i = 0; i < n; i++){ FPS f = {mint(1), mint(p[i])}; from_left[i+1] = from_left[i]*f; } for(int i = n-1; i >= 0; i--){ FPS f = {mint(1), mint(p[i])}; from_right[i] = from_right[i+1]*f; } int q; cin >> q; while(q--){ int a, b, k; cin >> a >> b >> k; a--; auto f = from_left[b]; f *= from_left[a].inv(k+1); if(f.size() >= k+1){ cout << f[k] << endl; }else{ cout << 0 << endl; } } }