/* -*- coding: utf-8 -*- * * 2283.cc: No.2283 Prohibit Three Consecutive - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ /* global variables */ char s[MAX_N + 4]; bool dp[MAX_N + 1][4]; /* subroutines */ /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int n; scanf("%d%s", &n, s); bool ok = false; for (int st = 0; ! ok && st < 4; st++) { int d0 = st >> 1, d1 = st & 1; if ((s[0] != '?' && s[0] - '0' != d0) || (s[1] != '?' && s[1] - '0' != d1)) continue; for (int i = 0; i <= n; i++) fill(dp[i], dp[i] + 4, false); dp[2][st] = true; for (int i = 2; i < n; i++) for (int bits = 0; bits < 4; bits++) if (dp[i][bits]) for (int di = 0; di < 2; di++) if ((s[i] == '?' || s[i] - '0' == di) && ! (bits == 0 && di == 0) && ! (bits == 3 && di == 1)) dp[i + 1][((bits << 1) | di) & 3] = true; ok = (dp[n][0] && d0 != 0) || (dp[n][1] && st != 3) || (dp[n][2] && st != 0) || (dp[n][3] && d0 != 1); } if (ok) puts("Yes"); else puts("No"); } return 0; }