#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int calculate_max_consecutive_ones(string s, int n) {
int max_consecutive_ones = 0;
int current_count = 0;
for (char c : s) {
if (c == '1') {
current_count++;
max_consecutive_ones = max(max_consecutive_ones, current_count);
} else {
current_count = 0;
}
}
return max_consecutive_ones;
}
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;
vector<int> flip_indices;
for (int i = 0; i < n; ++i) {
if (s[i] == '0') {
flip_indices.push_back(i);
}
}
int max_consecutive_ones = calculate_max_consecutive_ones(s, n);
// Simulate Roy's and Emon's turns
for (int i = 0; i < flip_indices.size(); ++i) {
int flip_index = flip_indices[i];
s[flip_index] = '1';
max_consecutive_ones = max(max_consecutive_ones, calculate_max_consecutive_ones(s, n));
// Flip back to the original to simulate Emon's turn
s[flip_index] = '0';
}
cout << max_consecutive_ones << endl;
}
return 0;
}