#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
int n;
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);
}
for(int i=0 ;i<n-1; i++){
if(s[i] == s[i+1])
v.push_back(1);
else if(s[i] != s[i+1])
v.push_back(0);
}
int x=0, y=0;
for(int i=0; i<v.size(); i++){
if(v[i] == 1)
x++;
else if(v[i] == 0)
y++;
}
if(y>x)cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCB0OwoJY2luID4+IHQ7Cgl3aGlsZSh0LS0pewoJCWludCBuOwoJCWNpbiA+PiBuOwoJCXZlY3RvcjxpbnQ+djsKCQlzdHJpbmcgczsKCQljaW4gPj4gczsKCQlmb3IoaW50IGk9MDsgaTxuOyBpKyspewoJCQlpbnQgayA9IHNbaV0gLSAnMCc7CgkJCXYucHVzaF9iYWNrKGspOwoJCX0KCQlmb3IoaW50IGk9MCA7aTxuLTE7IGkrKyl7CgkJCWlmKHNbaV0gPT0gc1tpKzFdKQoJCQkJdi5wdXNoX2JhY2soMSk7CgkJCWVsc2UgaWYoc1tpXSAhPSBzW2krMV0pCgkJCQl2LnB1c2hfYmFjaygwKTsKCQl9CgkJaW50IHg9MCwgeT0wOwoJCWZvcihpbnQgaT0wOyBpPHYuc2l6ZSgpOyBpKyspewoJCQlpZih2W2ldID09IDEpCgkJCQl4Kys7CgkJCWVsc2UgaWYodltpXSA9PSAwKQoJCQkJeSsrOwoJCX0KCQlpZih5PngpY291dCA8PCAiWUVTIiA8PCBlbmRsOwoJCWVsc2UKCQljb3V0IDw8ICJOTyIgPDwgZW5kbDsKCX0KCXJldHVybiAwOwp9