#include #define int long long using namespace std; #define fi first #define sc second #define pii pair #define pb push_back #define umap unordered_map #define mset multiset #define pq priority_queue #define ull unsigned long long #define i128 __int128 const int maxn=2e5+10; const int mod=998244353; int n,a[maxn],fr[maxn],ifr[maxn],vis[maxn]; vector vec; int quickpow(int x,int y){ int p=1; for(int i=y;i;i>>=1) p=(p*((i&1)?x:1))%mod,x=(x*x)%mod; return p; } int inv(int x){ return quickpow(x,mod-2); } void solve(){ cin>>n,fr[0]=1; for(int i=1;i<=n;i++) cin>>a[i],vis[a[i]]=1; for(int i=1;i<=n;i++) fr[i]=(fr[i-1]*i)%mod; ifr[n]=inv(fr[n]); for(int i=n-1;~i;i--) ifr[i]=(ifr[i+1]*(i+1))%mod; for(int i=1;i<=n;i++) if(!vis[i]) vec.pb(i); int maxx=0,res=0,cnt=0; for(int i=1;i<=n;i++){ maxx=max(maxx,a[i]); int pos=lower_bound(vec.begin(),vec.end(),maxx)-vec.begin(); if(a[i]==-1){ cnt++; int num=fr[vec.size()]*ifr[vec.size()-cnt]%mod; if(pos>=cnt) num=(num-fr[pos]*ifr[pos-cnt]%mod+mod)%mod; num=(num*inv(cnt)%mod*fr[vec.size()-cnt])%mod,res=(res+num)%mod; } else if(a[i]==maxx){ if(pos>=cnt) res=(res+fr[pos]*ifr[pos-cnt]%mod*fr[vec.size()-cnt]%mod)%mod; } } cout<>t; while(t--) solve(); return 0; } /* Samples input: output: THINGS TODO: ??freopen??????? ???? ???????????? */