#include <bits/stdc++.h>
using namespace std;
template<class T>
struct bit {
  int n;
  vector<T> a;
  bit() {}
  bit(int _n) : n(_n), a(n + 1) {}
  int lowbit(int x) { return x & -x; }
  T query(int p) {
    T res = 0;
    for (; p; p -= lowbit(p)) {
      res = max(res, a[p]);
    }
    return res;
  }
  void update(int p, T v) {
    for (; p <= n; p += lowbit(p)) {
      a[p] = max(a[p], v);
    }
  }
};

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    bit<int> b(n);
    vector<int> a(n + 1), d(n + 1);
    for (int i = 1; i <= n; ++i)
      scanf("%d", &a[i]);
    stack<pair<int, int>> stk;
    vector<vector<int>> val(n + 1, vector<int>());
    for (int i = n; i >= 1; --i) {
      while (!stk.empty() && stk.top().first < a[i]) {
        val[i].push_back(stk.top().second);
        stk.pop();
      }
      stk.push({a[i], i});
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      d[i] = max(d[i], b.query(a[i]) + 1);
      for (int p : val[i]) {
        d[p] = max(d[p], b.query(a[p]) + 2);
      }
      b.update(a[i], d[i]);
      ans = max(ans, d[i]);
    }
    printf("%d\n", ans);
  }
  return 0;
}
		 	 	  	 			 	 	 		     		 		