#include using namespace std; void solve() { int N; string s; cin >> N >> s; std::vector A(N) ; for (int i = 0; i < N; i ++) { A[i] = (s[i] == '?' ? 2 : s[i] - '0'); } auto OK = [&](int id) -> bool { while (id < 0) id += N; int p = id, q = (id + 1) % N, r = (id + 2) % N; return !(A[p] == A[q] && A[q] == A[r] && A[p] < 2); }; auto OK3 = [&](int id) -> bool { return OK(id - 1) && OK(id) && OK(id -2); }; queue que; vector inq(N, 0); for (int i = 0; i < N; i ++) { if (!OK(i)) { puts("No"); return; } if (A[i] < 2) { continue; } int cc = 0; for (int j = 0; j < 2; j ++) { A[i] = j; cc += !OK3(i); } if (cc == 2) { puts("No"); return; } A[i] = 2; if (cc == 1) { que.push(i); inq[i] = 1; } } while (!que.empty()) { int u = que.front(); que.pop(); A[u] = 0; if (!OK3(u)) { A[u] = 1; } if (!OK3(u)) { puts("No"); return; } for (int i = u - 2; i < u + 3; i ++) { int p = (i + N * 2) % N; if (A[p] < 2) { if (!OK3(p)) { puts("No"); return; } continue; } if (inq[p]) { continue; } int cc = 0; for (int j = 0; j < 2; j ++) { A[p] = j; cc += !OK3(p); } if (cc == 2) { puts("No"); return; } A[p] = 2; if (cc == 1) { que.push(p); inq[p] = 1; } } } for (int i = 0; i < N; i ++) { if (!OK(i)) { puts("No"); return; } } puts("Yes"); } int main () { int T; cin >> T; while (T --) { solve(); } }