#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); repd(p, 1, N){ rep(i, N){ up[i].first = 1; up[i].second = 0; } repd(i, p, N){ rep(j, i){ int fir = up[j].first + 1; int sec = A[i] - A[j]; if (fir > up[i].first) { if (sec > up[j].second) { up[i].first = fir; up[i].second = sec; } } if (fir == up[i].first) { if (sec > up[j].second) { up[i].second = min(up[i].second, sec); } } } } rep(i, N){ tempup[i] = max(tempup[i], up[i].first); } } repd(p, 1, N){ rep(i, N){ down[i].first = 1; down[i].second = 0; } repd(i, p, N){ rep(j, i){ int fir = down[j].first + 1; int sec = B[i] - B[j]; if (fir > down[i].first) { if (sec > down[j].second) { down[i].first = fir; down[i].second = sec; } } if (fir == down[i].first) { if (sec > down[j].second) { down[i].second = min(down[i].second, sec); } } } } rep(i, N){ tempdown[i] = max(tempdown[i], down[i].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; }