#include <bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

typedef __int128 LL;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

const int mod = 1e9+7;
const int inf = 1<<30;

struct abi {
    vector<int> t;
    abi ( int n ) {
        t = vector<int> (n+2);
    }
    void upd ( int p, int v ) {
        for ( int i = p+1; i < (int)t.size(); i += i&-i )  
            t[i] = max ( t[i], v );
    }
    int que ( int p ) {
        int ans = 0;
        for ( int i = p+1; i; i -= i&-i )
            ans = max ( ans, t[i] );
        return ans;
    }
};

int main() {
    #ifdef ernestico
        freopen ("a.in", "r", stdin );
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int t; cin >> t;
    while ( t-- ) {
        int n; cin >> n;
        vector<int> a(n+1);
        for ( int i = 1; i <= n; i ++ )
            cin >> a[i];
        
        vector<int> nxt(n+1);
        nxt[n] = n+1;
        for ( int i = n-1; i >= 0; i -- ) {
            nxt[i] = i+1;
            while ( nxt[i] != n+1 && a[i] >= a[ nxt[i] ] )
                nxt[i] = nxt[ nxt[i] ];
        }

        abi t(n);
        priority_queue<pair<int,pair<int,int>>> q;
        q.push ( { -1, { 0, 0 } } );
        for ( int i = 1; i <= n; i ++ ) {
            while ( !q.empty() && -q.top().F < i ) {
                int pos, val; tie(pos, val) = q.top().S;
                t.upd ( pos, val+1 );
                q.pop();
            }

            int tmp = t.que ( a[i] );
            t.upd ( a[i], tmp+1 );
            q.push ( {-nxt[i], {a[i], tmp+1} });
        }
        
        cout << t.que(n) << endl;
    }

    return 0;
}