#include #include #include #include #include #include #include #include #include #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) typedef long long ll; using namespace std; int inputValue(){ int a; cin >> a; return a; }; void inputArray(int * p, int a){ rep(i, a){ cin >> p[i]; } }; void inputVector(vector * p, int a){ rep(i, a){ int input; cin >> input; p -> push_back(input); } } template void output(T a, int precision) { if(precision > 0){ cout << setprecision(precision) << a << "\n"; } else{ cout << a << "\n"; } } int main(int argc, const char * argv[]) { // source code int T = inputValue(); vector R(T); rep(k, T){ int N = inputValue(); vector A(N); vector B(N); rep(i, N){ A[i] = inputValue(); B[N - i - 1] = A[i]; } // first: 最長系列の長さ second: 直前の差分 vector > up(N); vector tempup(N); vector > down(N); vector tempdown(N); rep(i, N){ tempup[i] = 0; tempdown[i] = 0; } //repd(i, 0, N){ repd(p, 0, N){ rep(q, N){ up[q].first = 1; up[q].second = 0; } repd(l, p + 1, N){ repd(j, p, l){ int fir = up[j].first + 1; int sec = A[l] - A[j]; if (fir > up[l].first) { if (sec > up[j].second) { up[l].first = fir; up[l].second = sec; } } if (fir == up[l].first) { if (sec > up[j].second) { up[l].second = min(up[l].second, sec); } } } } rep(q, N){ tempup[q] = max(tempup[q], up[q].first); } } //repd(i, 0, N){ repd(p, 0, N){ rep(q, N){ down[q].first = 1; down[q].second = 0; } repd(l, p + 1, N){ repd(j, p, l){ int fir = down[j].first + 1; int sec = B[l] - B[j]; if (fir > down[l].first) { if (sec > down[j].second) { down[l].first = fir; down[l].second = sec; } } if (fir == down[l].first) { if (sec > down[j].second) { down[l].second = min(down[l].second, sec); } } } } rep(q, N){ tempdown[q] = max(tempdown[q], down[q].first); } } vector sum(N); rep(i, N){ sum[i] = tempup[i] + tempdown[N - 1 - i] - 1; } int ret = -1; rep(i, N){ ret = max(ret, sum[i]); } R[k] = ret; } rep(i, T){ output(R[i], 0); } return 0; }