#include <bits/stdc++.h>
#define ll long long
using namespace std;

pair <int, int> get(int v, int tl, int tr, int l, int r, vector <pair <int, int> > & tree)
{
    if (tl == l && tr == r)
        return tree[v];

    pair <int, int> m1 = {0, 2}, m2 = {0, 2};
    int mid = (tl + tr) / 2;

    if (l <= mid)
        m1 = get(v * 2, tl, mid, l, min(r, mid), tree);

    if (r > mid)
        m2 = get(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, tree);

    return max(m1, m2);
}

void update(int v, int l, int r, int pos, pair <int, int> val, vector <pair <int, int> > & tree)
{
    if (l == r)
    {
        if (val > tree[v])
            tree[v] = val;

        return;
    }

    int mid = (l + r) / 2;

    if (pos <= mid)
        update(v * 2, l, mid, pos, val, tree);
    else
        update(v * 2 + 1, mid + 1, r, pos, val, tree);

    tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
    return;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int test;
    cin >> test;

    while (test--)
    {
        int n;
        cin >> n;
        vector <int> a(n);

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            a[i]--;
        }

        vector <int> closest_gr(n, -1);
        vector <int> cg_stack;

        for (int i = 0; i < n; i++)
        {
            while (cg_stack.size() && a[cg_stack.back()] <= a[i])
                cg_stack.pop_back();

            if (cg_stack.size())
                closest_gr[i] = cg_stack.back();

            cg_stack.push_back(i);
        }

        vector <pair <int, int> > tree(n * 4, {0, -2});

        int ans = 0;

        for (int i = 0; i < n; i++)
        {
            pair <int, int> prev = get(1, 0, n - 1, 0, a[i], tree);
            prev.second *= -1;

            if (prev.second < closest_gr[i] && closest_gr[i] != -1)
                prev.first += 2;
            else
                prev.first++;

            ans = max(ans, prev.first);
            update(1, 0, n - 1, a[i], {prev.first, -i}, tree);
        }

        cout << ans << "\n";
    }
}
