#include<bits/stdc++.h>
#define ll int
inline ll read(){
    char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
    ll k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
    while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return kk*k;
}using namespace std;
void write(ll x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
int t,n,a[1000010],ma[4000010],ans,f[1000010],flag[4000010],value[4000010];
void build(int l,int r,int d){
	ma[d]=flag[d]=0;
	if (l==r)return;
	int m=(l+r)>>1;
	build(l,m,d*2);build(m+1,r,d*2+1);
}
void clc(int d){
	if (!flag[d*2])flag[d*2]=1,ma[d*2]+=(ma[d*2]&1)==0;
	if (!flag[d*2+1])flag[d*2+1]=1,ma[d*2+1]+=(ma[d*2+1]&1)==0;
	flag[d]=0;
}
void putit(int x,int y,int l,int r,int d){
	if (l==r){
		if (ma[d]<=y*2){
			ma[d]=y*2;
			flag[d]=0;
			return;
		}
	}int m=(l+r)>>1;
	if (flag[d])clc(d);
	if (x<=m)putit(x,y,l,m,d*2);else putit(x,y,m+1,r,d*2+1);
	ma[d]=max(ma[d*2],ma[d*2+1]);
}
void put(int x,int l,int r,int d){
	if (flag[d])return;
	if (x>=r){
		flag[d]=1;ma[d]+=(ma[d]&1)==0;
		return;
	}int m=(l+r)>>1;
	if (x>m)put(x,m+1,r,d*2+1);
	put(x,l,m,d*2);
	ma[d]=max(ma[d*2],ma[d*2+1]);
	
}
int find(int x,int l,int r,int d){
	if (l==r)return ma[d];
	int m=(l+r)>>1;
	if (flag[d])clc(d);
	if (x<=m)return find(x,l,m,d*2);
		else return max(ma[d*2],find(x,m+1,r,d*2+1));
}
signed main(){
	t=read();
	while (t--){
		n=read();build(1,n,1);ans=0;
		for (int i=1;i<=n;i++){
			a[i]=read();
			if (a[i]>=a[i-1])f[i]=f[i-1]+1;else f[i]=0;
			f[i]=max(f[i],((find(a[i],1,n,1)+1)/2)+1);
			f[i]=min(f[i],i);
			ans=max(ans,f[i]);
			if (i>1)putit(a[i-1],f[i-1],1,n,1);
			put(a[i],1,n,1);
			//cout<<a[i]<<' '<<f[i]<<endl;
		}ans=min(ans,n);
		writeln(ans);
	}
}
