#include <iostream>
#include <vector>
#include <climits>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> dp_no_skip(n, LONG_MIN);
vector<long long> dp_skipping(n, LONG_MIN);
vector<long long> dp_after_skip(n, LONG_MIN);
long long max_rating = LONG_MIN;
dp_no_skip[0] = 0;
for (int i = 1; i < n; i++) {
if (a[i] > dp_no_skip[i-1]) {
dp_no_skip[i] = dp_no_skip[i-1] + 1;
} else if (a[i] == dp_no_skip[i-1]) {
dp_no_skip[i] = dp_no_skip[i-1];
} else {
dp_no_skip[i] = dp_no_skip[i-1] - 1;
}
if (i >= 1) {
dp_skipping[i] = dp_no_skip[i-1];
}
if (i >= 2) {
dp_after_skip[i] = dp_skipping[i-2];
}
max_rating = max(max_rating, dp_skipping[i]);
}
cout << max_rating << endl;
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y2xpbWl0cz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIHNvbHZlKCkgewogICAgaW50IG47CiAgICBjaW4gPj4gbjsKICAgIHZlY3RvcjxpbnQ+IGEobik7CiAgICAKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgY2luID4+IGFbaV07CiAgICB9CgogICAgdmVjdG9yPGxvbmcgbG9uZz4gZHBfbm9fc2tpcChuLCBMT05HX01JTik7CiAgICB2ZWN0b3I8bG9uZyBsb25nPiBkcF9za2lwcGluZyhuLCBMT05HX01JTik7CiAgICB2ZWN0b3I8bG9uZyBsb25nPiBkcF9hZnRlcl9za2lwKG4sIExPTkdfTUlOKTsKCiAgICBsb25nIGxvbmcgbWF4X3JhdGluZyA9IExPTkdfTUlOOwoKICAgIGRwX25vX3NraXBbMF0gPSAwOwoKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgaWYgKGFbaV0gPiBkcF9ub19za2lwW2ktMV0pIHsKICAgICAgICAgICAgZHBfbm9fc2tpcFtpXSA9IGRwX25vX3NraXBbaS0xXSArIDE7CiAgICAgICAgfSBlbHNlIGlmIChhW2ldID09IGRwX25vX3NraXBbaS0xXSkgewogICAgICAgICAgICBkcF9ub19za2lwW2ldID0gZHBfbm9fc2tpcFtpLTFdOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRwX25vX3NraXBbaV0gPSBkcF9ub19za2lwW2ktMV0gLSAxOwogICAgICAgIH0KCiAgICAgICAgaWYgKGkgPj0gMSkgewogICAgICAgICAgICBkcF9za2lwcGluZ1tpXSA9IGRwX25vX3NraXBbaS0xXTsKICAgICAgICB9CgogICAgICAgIGlmIChpID49IDIpIHsKICAgICAgICAgICAgZHBfYWZ0ZXJfc2tpcFtpXSA9IGRwX3NraXBwaW5nW2ktMl07CiAgICAgICAgfQoKICAgICAgICBtYXhfcmF0aW5nID0gbWF4KG1heF9yYXRpbmcsIGRwX3NraXBwaW5nW2ldKTsKICAgIH0KCiAgICBjb3V0IDw8IG1heF9yYXRpbmcgPDwgZW5kbDsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwogICAgCiAgICBmb3IgKGludCBpID0gMDsgaSA8IHQ7IGkrKykgewogICAgICAgIHNvbHZlKCk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=