#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; void solve() { int n; string s; cin >> n >> s; bool dp[2][2][2][2]{}; REP(a, 2) REP(b, 2) { if (s[0] != '0' + (a ^ 1) && s[1] != '0' + (b ^ 1)) dp[a][b][a][b] = true; } FOR(i, 2, n) { bool nxt[2][2][2][2]{}; REP(a, 2) REP(b, 2) REP(c, 2) REP(d, 2) { if (dp[a][b][c][d]) { REP(e, 2) { if ((c != d || d != e) && s[i] != '0' + (e ^ 1)) nxt[a][b][d][e] = true; } } } swap(dp, nxt); } REP(a, 2) REP(b, 2) REP(c, 2) REP(d, 2) { if (dp[a][b][c][d] && (c != d || d != a) && (d != a || a != b)) { cout << "Yes\n"; return; } } cout << "No\n"; } int main() { int t; cin >> t; while (t--) solve(); return 0; }