#include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) #define MOD 1000000007 #define MOD2 998244353 #define INF 1000000007 #define LINF 1000000000000000007LL #define PI 3.14159265359 #define P pair template inline bool chmax(T &a, const T &b){ if(a inline bool chmin(T &a, const T &b){ if(a>b) {a=b; return true;} else return false; } struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} }; typedef vector Edges; typedef vector Graph; void add_edge(Graph &g,int from,int to,ll cost,bool rev,ll rev_cost){ g[from].push_back(Edge(to,cost)); if(rev) g[to].push_back(Edge(from,rev_cost)); } template struct SegmentTree{ using F = function; int n; vector node; F combine; T identity; SegmentTree(int n, F combine, T identity) :n(n), node(n<<1, identity), combine(combine), identity(identity) {} void update(int i, T x){ if(i<0 || i>=n) return; node[i+=n] = x; while(i>>=1){ node[i]=combine(node[i<<1|0],node[i<<1|1]); } } T get(int i){ if(i<0 || i>=n) return identity; return node[i+n]; } T prod(int l, int r){ if(l>=r || l<0 || r>n) return identity; T Lres=identity; T Rres=identity; for(l+=n, r+=n; l>=1, r>>=1){ if(l&1) Lres = combine(Lres,node[l++]); if(r&1) Rres = combine(node[--r],Rres); } return combine(Lres,Rres); } }; void solve(){ int n; cin>>n; vector p(n); vector ind(n); rep(i,n) cin>>p[i]; rep(i,n) ind[p[i]]=i; auto f=[](int a,int b){return a+b;}; SegmentTree seg(n,f,0); rep(i,n) seg.update(i,1); int l=ind[0],r=ind[0]; seg.update(ind[0],0); ll ans=1; for(int i=1; ir){ seg.update(ind[i],0); chmin(l,ind[i]); chmax(r,ind[i]); } else{ ans *= seg.prod(l,r+1); ans %=MOD2; seg.update(ind[i],0); } } cout<