#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000LL
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;

#define endl '\n'
#define int ll

void insert(map<int,int> &mp, int key, int val) {
	int cur = std::prev(mp.upper_bound(key))->s;
	if(cur>=val) return;

	mp[key] = val;

	auto it = mp.upper_bound(key);
	while(it!=mp.end()) {
		int cur = it->s;
		if(cur>=val) break;

		auto it1 = it;
		it1++;

		mp.erase(it);

		it = it1;
	}
}

signed main() {
	
	fast;

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

		vector<int> v(n);
		for(int i=0;i<n;i++) cin>>v[i];

		stack<int> st;
		vector<int> prev[n];

		for(int i=0;i<n;i++) {
			while(st.size() && v[st.top()]<=v[i]) st.pop();

			if(st.size()) {
				prev[st.top()].pb(i);
			}

			st.push(i);
		}


		vector<int> dp(n, 1);

		map<int,int> mn;
		mn[-inf] = 0;

		for(int i=0;i<n;i++) {
			for(auto x: prev[i]) {
				int val = std::prev(mn.upper_bound(v[x]))->s + 2;
				dp[x] = max(dp[x], val);
			}
			int val = std::prev(mn.upper_bound(v[i]))->s + 1;
			dp[i] = max(dp[i], val);
			insert(mn, v[i], dp[i]);
		}

		int ans = 0;
		for(auto x: dp) ans = max(ans, x);

		// for(auto x: dp) cout<<"#"<<x<<endl;

		cout<<ans<<endl;
	}

}