#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
#define fst first
#define snd second

struct SegmentTree {
  VI tree;
  int sz;
  SegmentTree(int n) {
    for (sz = 1; sz < n; sz <<= 1)
      ;
    tree.resize(2 * sz);
  }
  /// set `a[i] = x`
  void update(int i, int x) {
    for (int node = sz + i; node >= 1; node >>= 1) {
      tree[node] = max(tree[node], x);
    }
  }
  /// maximum of range `[l, r)`
  int query(int l, int r, int node = 1, int x = 0, int y = -1) {
    if (y == -1) y = sz;
    if (l >= y || r <= x) return 0;
    if (l <= x && y <= r) return tree[node];
    return max(query(l, r, 2 * node, x, (x + y) / 2),
               query(l, r, 2 * node + 1, (x + y) / 2, y));
  }
  /// maximum of range `[0, lim]`
  int get(int lim) { return query(0, lim + 1); }
};

int solve() {
  int n;
  cin >> n;
  VI a(n);
  for (int &x : a)
    cin >> x, x--;

  VI nxt(n, n);
  stack<int> s;
  for (int i = n - 1; i >= 0; i--) {
    while (!s.empty() && a[s.top()] <= a[i])
      s.pop();
    if (!s.empty()) nxt[i] = s.top();
    s.push(i);
  }

  int ans = 0;
  set<PII> upd;
  SegmentTree st(n);
  VI dp(n);
  for (int i = 0; i < n; i++) {
    while (!upd.empty() && upd.begin()->fst < i) {
      int j = upd.begin()->snd;
      st.update(a[j], dp[j] + 1);
      upd.erase(upd.begin());
    }
    dp[i] = st.get(a[i]) + 1;
    if (i > 0) dp[i] = max(dp[i], 2);
    ans = max(ans, dp[i]);
    st.update(a[i], dp[i]);
    if (nxt[i] != n) {
      upd.emplace(nxt[i], i);
    }
  }

  return ans;
}

int main() {
#ifdef LOCAL_EXEC
  freopen("sample.in", "r", stdin);
  freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#endif

  int t;
  cin >> t;
  while (t--) {
    cout << solve() << '\n';
  }

  return 0;
}
