#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n, x=0, y=0;
cin >> n;
vector<int>v;
string s;
cin >> s;
for(int i=0; i<n; i++){
int k = s[i] - '0';
v.push_back(k);
if(v[i] == 1)x++;
else y++;
}
for(int i=0 ;i<n-1; i++){
if(s[i] != s[i+1]){
v.push_back(0);
y++;
}
if(y>x) break;
}
if(y>x)cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCB0OwoJY2luID4+IHQ7Cgl3aGlsZSh0LS0pewoJCWludCBuLCB4PTAsIHk9MDsKCQljaW4gPj4gbjsKCQl2ZWN0b3I8aW50PnY7CgkJc3RyaW5nIHM7CgkJY2luID4+IHM7CgkJZm9yKGludCBpPTA7IGk8bjsgaSsrKXsKCQkJaW50IGsgPSBzW2ldIC0gJzAnOwoJCQl2LnB1c2hfYmFjayhrKTsKCQkJaWYodltpXSA9PSAxKXgrKzsKCQkJZWxzZSB5Kys7CgkJfQoJCWZvcihpbnQgaT0wIDtpPG4tMTsgaSsrKXsKCQkJaWYoc1tpXSAhPSBzW2krMV0pewoJCQkJdi5wdXNoX2JhY2soMCk7CgkJCQl5Kys7CgkJCX0KCQkJaWYoeT54KSBicmVhazsKCQl9CgkJCgkJaWYoeT54KWNvdXQgPDwgIllFUyIgPDwgZW5kbDsKCQllbHNlCgkJY291dCA8PCAiTk8iIDw8IGVuZGw7Cgl9CglyZXR1cm4gMDsKfQ==