#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define endl '\n'
#define MIR183_PC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
void solve() {
// Your code here
ll n;
string s;
cin>>n>>s;
vector<ll>zv;
ll czero=0;
for (ll i=0;i<n;i++){
if (s[i]=='0'){
czero++;
}
else{
if(czero>0)zv.push_back(czero);
czero=0;
}
}
if (czero>0)zv.push_back(czero);
sort(zv.rbegin(),zv.rend());
ll mxones=0;
bool roy=true;
for (int i:zv){
if(roy){
mxones+=i;
}
roy=!roy;
}
cout<<mxones<<endl;
}
signed main() {
MIR183_PC;
// Always use ll, int may give TLE
ll tt;
// tt=1;
cin >> tt;
while (tt--) {
solve();
}
return 0;
}