#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Function to determine the maximum consecutive 1s in a string
int maxConsecutiveOnes(const string &s) {
int max_count = 0, count = 0;
for (char c : s) {
if (c == '1') {
count++;
max_count = max(max_count, count);
} else {
count = 0;
}
}
return max_count;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
// Vector to store the indices of '0's and '1's
vector<int> zero_indices, one_indices;
for (int i = 0; i < n; ++i) {
if (s[i] == '0') {
zero_indices.push_back(i);
} else {
one_indices.push_back(i);
}
}
// Both players play optimally
int left = 0, right = zero_indices.size() - 1;
bool roy_turn = true;
while (left <= right) {
if (roy_turn) {
// Roy's turn: flip a '0' to '1'
s[zero_indices[left]] = '1';
left++;
} else {
// Emon's turn: flip a '1' to '0'
s[zero_indices[right]] = '0';
right--;
}
roy_turn = !roy_turn;
}
cout << maxConsecutiveOnes(s) << endl;
}
return 0;
}