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