#include using namespace std; void solve() { int n; cin >> n; vector a(n); for (int i = 0; i < n; i ++) cin >> a[i]; vector b; for (int i = 0, j; i < n; i = j + 1) { b.push_back(a[i]); j = i; if (a[i] == 1) continue; while (j + 1 < n && a[j + 1] == a[i]) ++ j; } int cnt = 0; for (int x : b) if (x) ++ cnt; if (cnt >= b.size() - cnt) cout << "Yes\n"; else cout << "No\n"; } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int tt; cin >> tt; while (tt --) solve(); return 0; }