#include<bits/stdc++.h>

#define limit (int)(5e5 + 5)
#define mod (int)(1e9 + 7)
#define inf 1e16;

#define pb push_back
#define fi first
#define se second

using namespace std;

using lli = long long int;
using ld = long double;
using ulli = unsigned long long int;


int n;
int a[limit];
int dp[limit];
vector<pair<int,int>> st;
int ir[limit],lr[limit];

void ini()
{
	cin >> n;

	st.assign(4*n,{1,n+1});

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

	stack<pair<int,int>> s;


	for (int i = 0; i < n; ++i)
	{
		while(s.size() > 0 && s.top().fi < a[i])
			s.pop();

		if(s.size() > 0)
		{	
			auto t = s.top();
			ir[i] = t.se;
		}

		s.push({a[i],i});
	}

	return;
}

pair<int,int> maxe(pair<int,int> u,pair<int,int> v)
{
	if(u.fi != v.fi)
		return max(u,v);

	return min(u,v);
}

pair<int,int> update(pair<int,int> v,int in,int l,int r,int pos)
{
	if(in < l || in > r)
		return st[pos];

	if(l == r)
	{
		st[pos] = maxe(st[pos],v);
		return st[pos];
	}

	int mid = (l+r)/2;

	st[pos] = maxe(update(v,in,l,mid,2*pos+1) , update(v,in,mid+1,r,2*pos+2));
	return st[pos];
}

pair<int,int> query(int s,int e,int l,int r,int pos)
{
	if(s > r || e < l)
	{
		return {1,n+1};
	}

	if(s <= l && r <= e)
		return st[pos];

	int mid = (l+r)/2;

	return maxe(query(s,e,l,mid,2*pos+1),query(s,e,mid+1,r,2*pos+2));
}

int main()
{
	ios_base::sync_with_stdio (false); 
	cin.tie(NULL);

	int testn = 1;
	cin >> testn;

	for (int casen = 0; casen < testn; ++casen)
	{
		ini();

		dp[0] = 1;
		dp[1] = 2;
		update({dp[0],0},a[0],0,n-1,0);
		update({dp[1],1},a[1],0,n-1,0);
		lr[a[0]] = 0;
		lr[a[1]] = 1;
		

		pair<int,int> in;

		for (int i = 2; i < n; ++i)
		{
			in = query(0,a[i],0,n-1,0);

			if(in.se < ir[i])
				dp[i] = in.fi + 2;
			else
				dp[i] = in.fi + 1;

			update({dp[i],i},a[i],0,n-1,0);
		}

		int ans = 0;

		for (int i = 0; i < n; ++i)
		{
			// cout << dp[i] << " " << i << "\n";
			ans = max(ans,dp[i]);
		}

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

    return 0;
}