#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template inline void amin(T &x, U y) { if(y < x) x = y; } template inline void amax(T &x, U y) { if(x < y) x = y; } int main() { int T; scanf("%d", &T); rep(ii, T) { int N; scanf("%d", &N); vector A(N); rep(i, N) scanf("%d", &A[i]); vi dps[2]; rep(lr, 2) { vector > dp(N, vector(N+1, INF)); rep(i, N) dp[i][1] = 0; rep(i, N) reu(j, i+1, N) if(A[i] < A[j]) amin(dp[j][2], A[j] - A[i]); rep(i, N) rep(k, N+1) { int x = dp[i][k]; if(x == INF) continue; reu(j, i+1, N) if(A[i] < A[j] && x < A[j] - A[i]) amin(dp[j][k+1], A[j] - A[i]); } dps[lr].assign(N, 0); rep(i, N) rep(k, N+1) if(dp[i][k] != INF) amax(dps[lr][lr == 0 ? i : N - 1 - i], k); reverse(all(A)); } int ans = 1; rep(i, N) { // cerr << i << ": " << dps[0][i] << ", " << dps[1][i] << endl; amax(ans, dps[0][i] + dps[1][i] - 1); } printf("%d\n", ans); } return 0; }