// #pragma GCC optimize ("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target ("avx,avx2,fma") #include using std::cin, std::cout, std::cerr; using ll = long long; int main() { std::ios::sync_with_stdio(false); int T; cin >> T; while(T --) { int n; cin >> n; std::vector a(n); int x = 0, y = 0, cx = 0, cy = 0; for(int i = 0; i < n; i ++) { cin >> a[i]; if(a[i] == 0) x ++; else y ++; if(i > 0 && a[i] == a[i - 1]) { if(a[i] == 0) cx ++; else cy ++; } } if(x > y) { std::swap(x, y); std::swap(cx, cy); } if(y - cy <= x || std::min(x - cx, y - cy) >= 4) cout << "Yes\n"; else cout << "No\n"; } }