#include <algorithm>
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
const int N = 5e5 + 10;
int n;
int dp[N], f[N], a[N];
int lowbit(int x)
{
	return x & -x;
}
void change(int pos , int x)
{
	pos++;
	for (; pos <= n + 1; pos += lowbit(pos))
		f[pos] = max(f[pos], x);
}
int query(int pos)
{
	pos++;
	int res = 0;
	for (; pos > 0; pos -= lowbit(pos))
		res = max(res, f[pos]);
	return res;
}
void solve()
{
	cin >> n;
	stack<int>s;
	s.push(0);
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		dp[i] = query(a[i]) + 1;
		change(a[i], dp[i]);
		while (s.size() && a[s.top()] <= a[i])
		{
			change(a[s.top()], dp[s.top()] + 1);
			s.pop();
		}
		s.push(i);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
	cout << ans << endl;
	memset(f, 0, sizeof f);
}
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}