#include<bits/stdc++.h>
using namespace std;
int res(string &s){
int n = s.size();
vector<int> gaps;
int count1 = 0;
int max1 = 0;
bool gap = false;
for(int i=0; i<n; i++){
if(s[i]=='1'){
count1++;
max1 = max(max1,count1);
gap = false;
}
else{
if(count1>0){
gaps.push_back(count1);
count1 = 0;
}
gap = true;
}
}
if(count1>0) gaps.push_back(count1);
sort (gaps.rbegin(),gaps.rend());
int result=0;
for(int i=0; i<gaps.size(); i+=2){
result+=gaps[i];
}
return result;
}
int main(){
int t;
cin>>t;
while(t--){
int N;
string S;
cin>>N>>S;
cout<<res(S)<<endl;
}
return 0;
}