#define _CRT_SECURE_NO_WARNINGS #include #include #include #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) < (n) ; ++(i)) #define REPA(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i)) #if defined(_MSC_VER)||__cplusplus > 199711L #define AUTO(r,v) auto r = (v) #else #define AUTO(r,v) typeof(v) r = (v) #endif #define ALL(c) (c).begin() , (c).end() #define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();++it) #define LL long long #define int LL #define INF 99999999 #define DEV 1000000007 #define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0); using namespace std; int N; int Left[110][110]; int Right[110][110]; signed main() { QUICK_CIN; //ifstream cin("debug.txt"); //ofstream cout("result.txt"); cin >> N; REP(j, N){ int T; cin >> T; vector arr(T); vector max_left(T,1); vector max_right(T,1); fill(&Left[0][0], &Left[0][0] + 110 * 110, INF); fill(&Right[0][0], &Right[0][0] + 110 * 110, INF); REP(i, T){ cin >> arr[i]; } Left[0][0] = arr[0]; REP(m, T - 1){ Left[0][m + 1] = min(Left[0][m], arr[m + 1]); } int Llen; REPA(1,m, T-1){ bool update = false; REPA(m, n, T){ if (Left[m-1][n] < arr[n] ){ if (m<2||(m > 1 && Left[m - 1][n] - Left[m - 2][n] < arr[n] - Left[m - 1][n])){ Left[m][n] = min(arr[n], Left[m][n - 1]); update = true; } else{ Left[m][n] = Left[m][n - 1]; } } else{ Left[m][n] = Left[m][n - 1]; } if (Left[m][n] != INF){ max_left[n] = max(m+1,max_left[n]); } } if (!update){ Llen = m; break; } } std::reverse(ALL(arr)); Right[0][0] = arr[0]; REP(m, T - 1){ Right[0][m + 1] = min(Right[0][m], arr[m + 1]); } int Rlen; REPA(1, m, T - 1){ bool update = false; REPA(m, n, T){ if (Right[m - 1][n] < arr[n]){ if (m<2 || (m > 1 && Left[m - 1][n] - Right[m - 2][n] < arr[n] - Left[m - 1][n])){ Right[m][n] = min(arr[n], Right[m][n - 1]); update = true; } else{ Right[m][n] = Right[m][n - 1]; } } else{ Right[m][n] = Right[m][n - 1]; } if (Right[m][n] != INF){ max_right[n] = max(m + 1, max_right[n]); } } if (!update){ Rlen = m; break; } } int ma = 0; REP(i, T){ ma = max(ma, max_left[i] + max_right[T-1-i]-1); } cout << ma << endl; } return 0; }