#include <bits/stdc++.h>
using namespace std;
void result() {}
string resultstr() {
  string ans;
  return ans;
}
int resultint() {
  int ans;
  return ans;
}
long long resultlong(long long n) {
  long long c5;
  return c5;
}
bool checkValidity(long long a, long long b, long long c) {
  if (a + b <= c || a + c <= b || b + c <= a)
    return false;
  else
    return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long cnt = 0;
    string s;
    vector<long long> v;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      if (s.at(i) == '1') {
        cnt++;
      } else if (s.at(i) == '0') {
        v.push_back(cnt);
        cnt = 0;
      }
    }
    v.push_back(cnt);
    sort(v.begin(), v.end(), greater<int>());
    ;
    long long sum = 0;
    for (int i = 0; i < v.size(); i = i + 2) {
      sum += v[i];
    }
    cout << sum << "\n";
  }
}
