#include <bits/stdc++.h>
using namespace std;
int maxConsecutiveOnes(const string& S) {
int maxOnes = 0;
int currentOnes = 0;
vector<int> segments;
for (char c : S) {
if (c == '1') {
currentOnes++;
} else {
if (currentOnes > 0) {
segments.push_back(currentOnes);
maxOnes = max(maxOnes, currentOnes);
currentOnes = 0;
}
}
}
// In case the string ends with 1s
if (currentOnes > 0) {
segments.push_back(currentOnes);
maxOnes = max(maxOnes, currentOnes);
}
// The number of segments of 1s
int numSegments = segments.size();
// If there's only one segment of 1s, the answer is simple.
if (numSegments <= 1) {
return maxOnes;
}
int maxConsecutive = maxOnes;
for (int i = 0; i < numSegments - 1; i++) {
int combined = segments[i] + segments[i + 1];
maxConsecutive = max(maxConsecutive, combined);
}
return maxConsecutive;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int N;
cin >> N;
string S;
cin >> S;
cout << maxConsecutiveOnes(S) << "\n";
}
return 0;
}