#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define dbg(msg, var) cout << msg << " " << var << endl;
//

const int MAX = 200010;
const ll MOD = (int)1e9 +7;
const int INF = (int)1e9;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-8;

struct ST {
    ll id = 0;

    int size;
    vl operations;
    vector<pair<ll,ll>> mins;

    pair<ll,ll> merg(pair<ll,ll> a, pair<ll,ll> b) {
        if(a.ff > b.ff) {
            return a;
        }
        return b;
    }

    void init(int n) {
        size = 1;
        while(size < n) size *= 2;
        mins.assign(2*size, pair<ll,ll>(0, 0));
        operations.assign(2*size, 0);
    }

    void add(int l, int r, int v, int x, int lx, int rx) {
        if(r <= lx or l >= rx) return;
        if(l <= lx && rx <= r) {
            if(rx-lx == 1)
                mins[x].ss = lx;

            operations[x] += v;
            mins[x].ff += v;
            return;
        }

        int m = (rx + lx)/2;
        add(l, r, v, 2*x +1 , lx, m);
        add(l, r, v, 2*x +2 , m, rx);

        mins[x] = merg(mins[2*x +1], mins[2*x +2]);
        mins[x].ff += operations[x];
    }

    void add(int l, int r, int v) {
        add(l, r+1, v, 0, 0, size);
    }

    pair<ll,ll> mx(int l, int r, int x, int lx, int rx) {
        if(r <= lx or l >= rx) return mp(0, -1);
        if(l <= lx && rx <= r) {
            return mins[x];
        }

        int m = (lx + rx)/2;

        auto s1 = mx(l, r, 2*x +1, lx, m);
        auto s2 = mx(l, r, 2*x +2, m, rx);
        auto res = merg(s1, s2);
        res.ff += operations[x];

        return res;
    }

    pair<ll,ll> mx(int l, int r) {
        if(l > r) return mp(0LL, 0LL);
        return mx(l, r+1, 0, 0, size);
    }
};

int32_t main() {
    // sws;
    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;

        vi v(n);
        forn(i, n) {
            cin >> v[i];
        }

        ST st = ST();
        st.init(n+1);
        vector<vi> ant(n, vi());

        stack<pii> pilha;
        pilha.push(mp(0, 0));
        forn(i, n) {
            // pega normal
            auto val = st.mx(0, v[i]);
            auto eita = st.mx(v[i], v[i]);
            st.add(v[i], v[i], max(0LL, -eita.ff+val.ff+1));
            // cout << "v[i] = " << v[i] << " t[v[i]] " << eita.ff+max(0LL, -eita.ff+val.ff+1) << endl;


            // pega de graca
            while(pilha.size() and v[i] > pilha.top().ff) {
                auto t = pilha.top();
                auto ant = st.mx(t.ff, t.ff);
                if(ant.ff < t.ss+1) {
                    st.add(t.ff, t.ff, -ant.ff+t.ss+1);
                }

                pilha.pop();
            }

            pilha.push(mp(v[i], st.mx(v[i], v[i]).ff));
        }
        // forn(i, n) {
        //     cout << st.mx(i, i).ff << " ";
        // }
        // cout << endl;

        auto res = st.mx(0, n);
        cout << res.ff << endl;
    }

    // verificar limites, long long
    return 0;
}
