#include<iostream> #include<vector> #include<algorithm> #include<cstring> #define int long long
usingnamespace std;
constint N = 2e6, mod = 998244353; int fac[N + 10], ifac[N + 10], inv[N + 10]; int q[N], vis[N]; intC(int n, int m){ if (m > n || m < 0) return0; return fac[n] * ifac[m] % mod * ifac[n - m] % mod; }
intcalc(int x, int y, int n, int m){ return (mod + C(n - x + m - y, n - x + 1) + C(n - x, m - x + 2) - C(m - x + n - y, m - x + 2)) % mod; }
signedmain(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T, n; cin >> T; fac[0] = fac[1] = ifac[0] = ifac[1] = inv[1] = 1; for (int i = 2; i <= N; ++i) { inv[i] = (mod - mod / i) * inv[mod % i] % mod; ifac[i] = ifac[i - 1] * inv[i] % mod; fac[i] = fac[i - 1] * i % mod; } while (T--) { cin >> n; memset(vis, 0, sizeof(vis)); int ans = 0; int Max = 0; int mn = 1; for (int i = 1; i <= n; ++i) { cin >> q[i]; vis[q[i]] = 1; ans = (ans + calc(i, max(Max, q[i]), n, n)) % mod; if (Max < q[i]) Max = q[i]; else { if (q[i] != mn) { for (int j = i + 1; j <= n; ++j) { cin >> q[j]; } break; } } while (vis[mn]) ++mn; } cout << ans << endl; } return0; }