#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) {
int N;
string S;
cin >> N >> S;
vector<int> segments;
int count = 0;
// Collect all segments of consecutive '1's
for (int i = 0; i < N; ++i) {
if (S[i] == '1') {
++count;
} else {
if (count > 0) {
segments.push_back(count);
}
count = 0;
}
}
// Add the last segment if it ends with '1'
if (count > 0) {
segments.push_back(count);
}
// Sort segments in descending order to simulate optimal play
sort(segments.rbegin(), segments.rend());
// Roy's optimal score: sum the lengths of every other segment (1st, 3rd, etc.)
int max_consecutive_1s = 0;
for (int i = 0; i < segments.size(); i += 2) {
max_consecutive_1s += segments[i];
}
cout << max_consecutive_1s << endl;
}
return 0;
}