#ifdef DEBUG #define _GLIBCXX_DEBUG #define CERR( ANSWER ) cerr << ANSWER << "\n"; #else #pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #define CERR( ANSWER ) #endif #include using namespace std; #define ATT __attribute__( ( target( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) ) ) #define TYPE_OF( VAR ) decay_t #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) ) #define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) #define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) #define QUIT return 0 #define COUT( ANSWER ) cout << ( ANSWER ) << "\n" int main() { UNTIE; CEXPR( int , bound_T , 50000 ); CIN_ASSERT( T , 1 , bound_T ); CEXPR( int , bound_N , 100000 ); const string O = "1"; const string D[4][2] = { { "0" , "0" } , { "0" , "1" } , { "1" , "0" } , { "1" , "1" } }; const string Yes = "Yes"; const string No = "No"; REPEAT( T ){ CIN_ASSERT( N , 3 , bound_N ); CIN( string , S ); set T{}; const string S0 = S.substr( 0 , 1 ); const string S1 = S.substr( 1 , 1 ); FOR( i , 0 , 4 ){ const string ( &Di )[2] = D[i]; T.insert( ( S0 > O ? Di[0] : S0 ) + ( S1 > O ? Di[1] : S1 ) ); } char f = 0; FOR_ITR( T , itr , end ){ char a = 1; char b = 1; char c = 1; char d = 1; const string& t = *itr; FOR( i , 0 , 2 ){ const string s = t.substr( i , 1 ); const bool p = s != O; const bool q = s >= O; const char a_next = p ? c : 0; const char b_next = q ? a | c : 0; const char c_next = p ? b | d : 0; const char d_next = q ? b : 0; a = a_next; b = b_next; c = c_next; d = d_next; } FOR( i , 2 , N ){ const string s = S.substr( i , 1 ); const bool p = s != O; const bool q = s >= O; const char a_next = p ? c : 0; const char b_next = q ? a | c : 0; const char c_next = p ? b | d : 0; const char d_next = q ? b : 0; a = a_next; b = b_next; c = c_next; d = d_next; } FOR( i , 0 , 2 ){ const string s = t.substr( i , 1 ); const bool p = s != O; const bool q = s >= O; const char a_next = p ? c : 0; const char b_next = q ? a | c : 0; const char c_next = p ? b | d : 0; const char d_next = q ? b : 0; a = a_next; b = b_next; c = c_next; d = d_next; } f |= a | b | c | d; } COUT( f > 0 ? Yes : No ); } QUIT; }