#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; bool solver(int f, int N, string S) { if (f >> 1 & 1) { S[0] = '1'; S.append("1"); } else { S[0] = '0'; S.append("0"); } if (f >> 0 & 1) { S[1] = '1'; S.append("1"); } else { S[1] = '0'; S.append("0"); } bool is_valid[N + 2][4]; memset(is_valid, false, sizeof(is_valid)); is_valid[1][f] = true; for (int i = 2; i < N + 2; ++i) { for (int mask = 0; mask < 4; ++mask) { if (not is_valid[i - 1][mask]) continue; switch(mask) { case 0: if (S[i] == '1' || S[i] == '?') { is_valid[i][1] = true; } break; case 1: if (S[i] == '0' || S[i] == '?') { is_valid[i][2] = true; } if (S[i] == '1' || S[i] == '?') { is_valid[i][3] = true; } break; case 2: if (S[i] == '0' || S[i] == '?') { is_valid[i][0] = true; } if (S[i] == '1' || S[i] == '?') { is_valid[i][1] = true; } break; case 3: if (S[i] == '0' || S[i] == '?') { is_valid[i][2] = true; } break; } } bool valid = false; for (int mask = 0; mask < 4; ++mask) { valid |= is_valid[i][mask]; } if (not valid) { return false; } } return true; } int main() { int T; cin >> T; for (int t = 0; t < T; ++t) { int N; string S; cin >> N; cin >> S; bool res = false; for (int mask = 0; mask < 4; ++mask) { bool ok = true; for (int i = 0; i < 2; ++i ){ if (mask >> i & 1) { ok &= (S[1 - i] == '1' || S[1 - i] == '?'); } else { ok &= (S[1 - i] == '0' || S[1 - i] == '?'); } } if (ok) { res |= solver(mask, N, S); } } if (res) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }