#include<bits/stdc++.h>

using namespace std;

#define task "sol"
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define zs(v) ((int)(v).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define CNTBIT __builtin_popcountll
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int dx[4]={-1, 0, 1, 0}, dy[4]={0, 1, 0, -1};
const int dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};

const ll mod=1000000007; /// 998244353
const int base=311;
const int N=5e5+5;

struct segtree
{
    vector<int> st;
    void kc(int n)
    {
        st.assign(4*n+5,0);
    }
    void upd(int i, int l, int r, int p, int val)
    {
        if(l==r)
        {
            st[i]=max(st[i],val);
            return;
        }
        int mid=(l+r)>>1;
        if(p<=mid) upd(i<<1,l,mid,p,val);
        else upd(i<<1|1,mid+1,r,p,val);
        st[i]=max(st[i<<1],st[i<<1|1]);
    }
    int get(int i, int l, int r, int u, int v)
    {
        if(u>r||v<l) return 0;
        if(u<=l&&r<=v) return st[i];
        int mid=(l+r)>>1;
        return max(get(i<<1,l,mid,u,v),get(i<<1|1,mid+1,r,u,v));
    }
};
int n,a[N];
segtree IT;
vector<int> dsk[N];
int nxt[N];

void gogo()
{
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];

    stack<int> s;
    for(int i=n;i>=1;--i)
    {
        nxt[i]=n+1;
        while(zs(s)&&a[i]>a[s.top()]) s.pop();
        if(zs(s)) nxt[i]=s.top();
        s.push(i);
    }

    for(int i=1;i<=n;++i)
    {
        dsk[nxt[i]].pb(i);
    }

//    for(int i:dsk[3]) cout<<i<<endl;

    IT.kc(n);
    for(int i=1;i<=n;++i)
    {
        int val=IT.get(1,1,n,1,a[i])+1;

        if(i>=2) val=max(val,2);

        for(int j:dsk[i])
        {
            int res=IT.get(1,1,n,a[j],a[j])+1;
            IT.upd(1,1,n,a[j],res);
        }
        IT.upd(1,1,n,a[i],val);
    }
    cout<<IT.st[1]<<'\n';

    for(int i=1;i<=n+1;++i) dsk[i].clear();
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    int t;
    cin>>t;
    while(t--) gogo();
    return 0;
}




