#include using i64 = long long; void solve() { int N; std::cin >> N; std::string S; std::cin >> S; for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { if (S[0] == '0' + !x) { continue; } if (S[1] == '0' + !y) { continue; } std::array, 2> dp{}; dp[x][y] = true; for (int i = 2; i < N; i++) { std::array, 2> g{}; for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { for (int z = 0; z < 2; z++) { if (dp[x][y] && S[i] != '0' + !z && (x != y || y != z)) { g[y][z] = true; } } } } dp = g; } for (int t = 0; t < 2; t++) { for (int z = 0; z < 2; z++) { if ((t != z || z != x) && (z != x || x != y) && dp[t][z]) { std::cout << "Yes\n"; return; } } } } } std::cout << "No\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t--) { solve(); } return 0; }