#include using namespace std; typedef long long ll; typedef vector< int > vi; typedef vector< vi > vvi; typedef vector< ll > vl; typedef vector< vl > vvl; typedef pair< int, int > pii; typedef vector< pii > vp; typedef vector< double > vd; typedef vector< vd > vvd; typedef vector< string > vs; template< class T1, class T2 > int upmin( T1 &x, T2 v ){ if( x > v ){ x = v; return 1; } return 0; } template< class T1, class T2 > int upmax( T1 &x, T2 v ){ if( x < v ){ x = v; return 1; } return 0; } const int INF = 0x3f3f3f3f; int N; vi A; void init(){ cin >> N; A = vi( N ); for( int i = 0; i < N; ++i ) cin >> A[ i ]; } vvi dp; vvi rdp; void preprocess(){ dp = vvi( N, vi( N, -INF ) ); for( int i = 0; i < N; ++i ) for( int j = i + 1; j < N; ++j ) if( A[ i ] < A[ j ] ) upmax( dp[ i ][ j ], 1 ); for( int i = 0; i < N; ++i ) for( int j = i + 1; j < N; ++j ) if( dp[ i ][ j ] > -INF ) for( int k = j + 1; k < N; ++k ) if( A[ k ] - A[ j ] > A[ j ] - A[ i ] ) upmax( dp[ j ][ k ], dp[ i ][ j ] + 1 ); rdp = vvi( N, vi( N, -INF ) ); for( int i = 0; i < N; ++i ) for( int j = i + 1; j < N; ++j ) if( A[ i ] > A[ j ] ) upmax( rdp[ i ][ j ], 1 ); for( int i = N - 1; i > 0; --i ) for( int j = i - 1; j > 0; --j ) if( rdp[ j ][ i ] > -INF ) for( int k = j - 1; k >= 0; --k ) if( A[ k ] - A[ j ] > A[ j ] - A[ i ] ) upmax( rdp[ k ][ j ], rdp[ j ][ i ] + 1 ); } void solve(){ int ans = 1; for( int i = 0; i < N; ++i ){ int lmax = 0; for( int j = 0; j < i; ++j ) upmax( lmax, dp[ j ][ i ] ); int rmax = 0; for( int j = i + 1; j < N; ++j ) upmax( rmax, rdp[ i ][ j ] ); upmax( ans, lmax + 1 + rmax ); } cout << ans << endl; } signed main(){ ios::sync_with_stdio( 0 ); int T; cin >> T; for( int kase = 0; kase < T; ++kase ){ init(); preprocess(); solve(); } return 0; }