#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int maxConsecutiveOnes(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 calculateMaxConsecutiveOnes(int n, string s) {
vector<int> segments;
int current_segment = 0;
for (char c : s) {
if (c == '1') {
current_segment++;
} else {
if (current_segment > 0) {
segments.push_back(current_segment);
}
current_segment = 0;
}
}
if (current_segment > 0) {
segments.push_back(current_segment);
}
sort(segments.rbegin(), segments.rend());
int max_consecutive_ones = 0;
for (int i = 0; i < segments.size(); i += 2) {
max_consecutive_ones += segments[i];
}
return max_consecutive_ones;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
cout << calculateMaxConsecutiveOnes(n, s) << endl;
}
return 0;
}