#include using namespace std; static const long long INF = (1LL << 60); int N; vector A; // f(p, d, delta) をメモ化するためのキー struct Key { int p; long long d; int delta; bool operator==(const Key &o) const { return p == o.p && d == o.d && delta == o.delta; } }; // unordered_map のための hash 関数 struct KeyHash { size_t operator()(Key const &k) const noexcept { return ((size_t)k.p * 1315423911u) ^ ((size_t)k.d + 0x9e3779b97f4a7c15ULL) ^ (k.delta << 1); } }; unordered_map memo; int f(int p, long long d, int delta) { Key key{p, d, delta}; auto it = memo.find(key); if (it != memo.end()) return it->second; int res = 0; for (int i = p + delta; 0 <= i && i < N; i += delta) { long long d2 = llabs(A[p] - A[i]); if (d2 < d && A[i] < A[p]) { res = max(res, f(i, d2, delta) + 1); } } memo[key] = res; return res; } int solve() { cin >> N; A.resize(N); for (int i = 0; i < N; i++) cin >> A[i]; memo.clear(); int res = 0; for (int i = 0; i < N; i++) { res = max(res, f(i, INF, -1) + f(i, INF, 1) + 1); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { cout << solve() << "\n"; } }