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

#define l long long
#define mod 1000000007
#define ii pair<l,l>
#define jj pair<ii,l>
#define zero 0LL

class Fenwick{
	l ar[500009];
	l N;
public:
	Fenwick(int n){
		memset(ar,0,sizeof(ar));
		this->N=n;
	}

	void update(l i,l val){
		while(i<=N){
			ar[i]=max(ar[i],val);
			i += i&-i;
		}
	}

	l maxVal(l i){
		l val=0;
		while(i){
			val=max(val,ar[i]);
			i -= i&-i;
		}
		return val;
	}
};

class Problem {

public:
	void solve(){
		int t;cin>>t;
		while(t--){
			l n;cin>>n;
			l ar[n+1];ar[0]=1; // Add a dummy element 1 in the beginning
			// so that the lis can always start from this
			// this allows us to use the fenwick tree for getting the max
			// value from beginning of the array.
			for(int i=1;i<=n;i++)cin>>ar[i];
			l dp[n+1];memset(dp,0,sizeof(dp));
			Fenwick fw(n);
			stack<l>st;
			l ans=0;
			for(int i=0;i<=n;i++){
				dp[i]=fw.maxVal(ar[i])+1;
				fw.update(ar[i],dp[i]);

				while(!st.empty()&& ar[i]>=ar[st.top()]){
					fw.update(ar[st.top()],dp[st.top()]+1);
					st.pop();
				}
				st.push(i);
				ans=max(ans,dp[i]);
			}
			cout<<ans-1<<endl;
		}
	}
};

int main()
{
	Problem p;
	p.solve();
}

