#include #define int long long using namespace std; const int N=5005,M=998244353; int n,q,p[N],a,b,k; struct poly{ int n,f[N]; void clear(){memset(f,0,sizeof f);} poly(){clear();} }ans,other; poly operator*(poly a,poly b){ poly c; c.n=min(a.n+b.n,k); for(int i=0;i<=c.n;i++)for(int j=0;j<=min(i,b.n);j++)c.f[i]=(c.f[i]+a.f[i-j]*b.f[j]%M)%M; return c; } void operator*=(poly&a,poly b){ a=a*b; } signed main(){ cin>>n; for(int i=1;i<=n;i++)cin>>p[i],p[i]=(p[i]%M+M)%M; cin>>q; while(q--){ cin>>a>>b>>k; ans.clear();ans.n=k,ans.f[0]=1; for(int i=a;i<=b;i++)other.n=1,other.f[0]=1,other.f[1]=p[i],ans*=other; cout<