#include #include int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t --> 0) { int n; std::cin >> n; std::vector p(n); for (auto &e : p) { std::cin >> e; --e; } std::vector q(n), r(n, 1); for (int i = 0; i < n; ++i) { q[p[i]] = i; } int sep_num = 0; auto update = [&](int i, int v) { sep_num -= i > 0 and r[i - 1] != r[i]; sep_num -= i + 1 < n and r[i + 1] != r[i]; r[i] = v; sep_num += i > 0 and r[i - 1] != r[i]; sep_num += i + 1 < n and r[i + 1] != r[i]; }; int ans = 0; for (int i : q) { update(i, -1); int len = sep_num + 1; len -= i > 0 and r[i - 1] == 1; len -= i + 1 < n and r[i + 1] == 1; ans = std::max(ans, len); update(i, 0); } std::cout << ans << '\n'; } return 0; }