
 
#include <bits/stdc++.h>

using namespace std;

 
#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

 
const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 5e5 + 5;
 
int i, n, a[N], dp[N], st[4 * N], nxt[N];
vi pre[N];
 
void build(int v, int tl, int tr)
{
	if (tl == tr)
	{
		st[v] = dp[tl];
		return;
	}
	int tm = (tl + tr) / 2;
	build(2 * v, tl, tm);
	build(2 * v + 1, tm + 1, tr);
	st[v] = max(st[2 * v], st[2 * v + 1]);
}
 
void update(int v, int tl, int tr, int pos, int val)
{
	if (tl > pos || tr < pos)
		return;
	if (tl == tr)
	{
		st[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	update(2 * v, tl, tm, pos, val);
	update(2 * v + 1, tm + 1, tr, pos, val);
	st[v] = max(st[2 * v], st[2 * v + 1]);
}
 
int query(int v, int tl, int tr, int l, int r)
{
	if (tl > r || tr < l)
		return 0;
	if (l <= tl && tr <= r)
		return st[v];
	int tm = (tl + tr) / 2;
	int q1 = query(2 * v, tl, tm, l, r);
	int q2 = query(2 * v + 1, tm + 1, tr, l, r);
	return max(q1, q2);
}
 
void solve()
{
	cin >> n;
	for (i = 0; i <= n; i++)
	{
		dp[i] = 0;
		nxt[i] = -1;
		pre[i].clear();
	}
	build(1, 0, n);
	a[0] = 0;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	stack<pii> s;
	for (i = n; i >= 0; i--)
	{
		while (!s.empty() && s.top().f < a[i])
			s.pop();
		if (!s.empty())
			nxt[i] = s.top().s;
		else
			nxt[i] = -1;
		s.push({a[i], i});
		if (nxt[i] != -1)
			pre[nxt[i]].pb(i);
	}
	for (i = 1; i <= n; i++)
	{
		dp[i] = max(dp[i], query(1, 0, n, 0, a[i]) + 1);
		update(1, 0, n, a[i], dp[i]);

		for (int j : pre[i])
		{
			dp[j]++;
			update(1, 0, n, a[j], dp[j]);
		}
		//printf("%lld ",dp[i]); 
	}
//	puts("");
	int ans = query(1, 0, n, 0, n);
	cout << ans << endl;
}
 
signed main()
{

	int t;
	cin >> t;
	//t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}