#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 struct Data{ vector> v; Data(){ v.resize(2,vector(2,-Inf)); } }; Data op(Data a,Data b){ Data ret; rep(i,2){ rep(j,2){ ret.v[i][j] = max(ret.v[i][j],a.v[i][j]); ret.v[i][j] = max(ret.v[i][j],b.v[i][j]); rep(k,2){ rep(l,2){ if(j==k)continue; ret.v[i][l] = max(ret.v[i][l], a.v[i][j] + b.v[k][l]); } } } } return ret; } Data e(){ return Data(); } int main(){ int _t; cin>>_t; rep(_,_t){ int n; cin>>n; vector pos(n); rep(i,n){ int p; cin>>p; p--; pos[p] = i; } segtree seg(n); rep(i,n){ Data t; t.v[0][0] = 1; seg.set(i,t); } int ans = 0; rep(i,n){ Data t; t.v[1][1] = 1; auto x = seg.prod(0,pos[i]); auto y = seg.prod(pos[i]+1,n); int z = 1; z += max({0,x.v[0][0] , x.v[1][0]}); z += max({0,y.v[0][0] , y.v[0][1]}); // cout<