// "C:\Users\ianli\Desktop\CP\template\"
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define MTP make_tuple
typedef long long int ll;
constexpr int kN = int(5E5 + 10);

struct BIT {
	int val[kN];
	int sz;
	void init(int n) {
		sz = n + 2;
		memset(val, 0, sizeof(int) * sz);
	}
	void add(int pos, int x) {
		pos++;
		while (pos < sz) {
			val[pos] = max(val[pos], x);
			pos += pos & -pos;
		}
		return ;
	}
	int ask(int pos) {
		pos++;
		int ans = 0;
		while (pos) {
			ans = max(ans, val[pos]);
			pos ^= pos & -pos;
		}
		return ans;
	}
};

int val[kN], a[kN]; 
BIT bit;

void solve() {
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; // (a[i], val[i])
	int n, ans = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	pq.push(MP(0, 0));
	bit.init(n);

	for (int i = 1; i <= n; i++) {
		val[i] = bit.ask(a[i]) + 1;
		//for (int j = 0; j < i; j++) {
		//	if (a[i] >= a[j]) {
		//		val[i] = max(val[i], g[j] + 1);
		//		val[i] = max(val[i], val[j] + 1);
		//		g[j] = max(g[j], val[j] + 1);
		//	}
		//}
		while (!pq.empty()) {
			if (a[i] >= pq.top().F) {
				bit.add(pq.top().F, pq.top().S + 1);
				pq.pop();
			}
			else break;
		}
		bit.add(a[i], val[i]);
		pq.push(MP(a[i], val[i]));
	}

	ans = bit.ask(n);
	for (int i = 1; i <= n; i++) ans = max(ans, val[i]);

	printf("%d\n", ans);
	return ;
}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int t;
	scanf("%d", &t);
	for (int i = 1; i <= t; i++) {
		solve();
	}
}
