#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
string s;
cin >> n >> s;
// If Roy starts and there are more 1s, then he will always choose the index with 1, thus the max consecutive 1s is the length of the string
if (count(s.begin(), s.end(), '1') > count(s.begin(), s.end(), '0')) {
cout << n << endl;
} else {
// If Roy starts and there are more 0s, then he will always choose the index with 1, thus the max consecutive 1s is the length of the string
if (count(s.begin(), s.end(), '1') < count(s.begin(), s.end(), '0')) {
cout << n << endl;
} else {
// If Roy starts and there are equal number of 0s and 1s, then he will always choose the index with 1, thus the max consecutive 1s is the length of the string
cout << n << endl;
}
}
}
return 0;
}