//#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using lg = long long; #define TEST clog << "TEST" << endl #define IINF 2147483647 #define LLINF 9223372036854775807LL #define AMARI 998244353 #define TEMOTO ((sizeof(long double) == 16) ? false : true) #define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000) #define el '\n' #define El '\n' #define MULTI_TEST_CASE true void solve(void) { int n; string s; cin >> n >> s; for (int i = 0; i < n; i++)s.push_back(s[i]); vector zyoutai(2 * n); //zyoutai[i] == 0 0のみ取り得る 1:1のみ取り得る 2:0も1も取り得る if (s[0] == '0')zyoutai[0] = 0; if (s[0] == '1')zyoutai[0] = 1; if (s[0] == '?')zyoutai[0] = 2; if (s[1] == '0')zyoutai[1] = 0; if (s[1] == '1')zyoutai[1] = 1; if (s[1] == '?')zyoutai[1] = 2; for (int i = 2; i < 2 * n; i++) { //clog << i << el; if (s[i] == '0')zyoutai[i] = 0; if (s[i] == '1')zyoutai[i] = 1; if (s[i] == '?') { if (zyoutai[i - 1] && zyoutai[i - 2] && zyoutai[i - 1] != 2)zyoutai[i] = zyoutai[i - 1] ^ 1; else zyoutai[i] = 2; } } for (int i = 0; i < 2 * n - 2; i++) { if (zyoutai[i] == zyoutai[i + 1] && zyoutai[i + 1] == zyoutai[i + 2] && zyoutai[i] != 2) { cout << "No" << el; return; } } cout << "Yes" << El; return; } void calc(void) { return; } int main(void) { cin.tie(nullptr); ios::sync_with_stdio(false); int t = 1; if (MULTI_TEST_CASE)cin >> t; while (t--) { solve(); } calc(); return 0; }