#include <bits/stdc++.h> 
using namespace std; 
#define int long long
#define double long double
#define pb push_back

struct  stnode
{
    int ma; 
};
stnode st[2000005];
int n;

int arr[500005];
int qry[500005];
vector< vector<int> > q;
void merge(stnode &f,stnode &n1,stnode &n2)
{
   f.ma=max(n1.ma,n2.ma);
}
void build(int node ,int l ,int r)
{
    if(l==r)
    {
        st[node].ma=0;
        return ; 
    }
    int m=(l+r)/2;
    build(2*node , l, m);
    build(2*node + 1, m+1 ,r);
    merge(st[node],st[2*node],st[2*node +1]);
 
}
  
void update(int node,int l,int r,int pos,int val)
{
    if(l==r)
    {
        st[node].ma=max(st[node].ma,val);
    }
    else
    {
        int mid=(l+r)/2;
        if(pos<=mid)
            update(2*node , l ,mid,pos,val);
        else
            update(2*node +1 , mid +1 ,r,pos,val);
        merge(st[node],st[2*node],st[2*node + 1]);
        //cout<<ind<<" "<<st[ind].best<<"\n";
    }
}
 
stnode query(int ind, int l, int r, int lo, int hi)
{
    if(l==lo && r==hi)
        return st[ind];
    int mid =(l+r)/2;
    if(lo > mid)
        return query(2*ind + 1,mid +1,r,lo,hi);
    if(hi<=mid)
        return query(2*ind,l,mid,lo,hi);
    stnode left = query(2*ind, l, mid,lo,mid);
    stnode right = query(2*ind +1, mid +1,r,mid + 1,hi);
    stnode result ;
    merge(result,left,right);
    return result;
}

int32_t main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        cin >> n;
        for(int i = 1; i <= n; i++)
            cin >> arr[i], qry[i] = -1;
        build(1, 1, n);
        stack <int> s;
        s.push(1);
        q.clear();
        q.resize(n + 5);
        for(int i = 2; i <= n; i++)
        {
            while(!s.empty() && arr[s.top()] < arr[i])
                s.pop();
            if(!s.empty())
                qry[i] = s.top(), q[s.top()].pb(i);
            s.push(i);
        }
        /*for(int i = 1; i <= n; i++)
            cout << qry[i] << " ";
        cout << "\n";*/

        int ans = 0;
        for(int i = 1; i <= n; i++)
        {
            for(auto &k: q[i])
                qry[k] = query(1, 1, n, 1, arr[k]).ma;
            int x = query(1, 1, n, 1, arr[i]).ma + 1;
            x = max(x , qry[i] + 2);
            update(1, 1, n, arr[i], x);
            ans = max(ans, x);
        }
        cout << ans << "\n";
    }
}