#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int arrg[1000000];
int nxt() {
  int x;
  cin >> x;
  return x;
}
long long lxt() {
  long long x;
  cin >> x;
  return x;
}
double dxt() {
  double x;
  cin >> x;
  return x;
}
long double ldxt() {
  long double x;
  cin >> x;
  return x;
}
bool cmp(const pair<int, int> &p, const pair<int, int> &q) {
  if (p.first < q.first)
    return 1;
  else if (p.first == q.first)
    return (p.second < q.second);
  else
    return 0;
}
int main() {
  int tc;
  cin >> tc;
  for (int z = 1; z <= tc; z++) {
    string s;
    cin >> s;
    long long cnt = 0;
    vector<long long> v;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '0') {
        v.emplace_back(cnt);
        cnt = 0;
      } else
        cnt++;
    }
    v.emplace_back(cnt);
    sort((v).begin(), (v).end(), greater<int>());
    long long sum = 0;
    for (long long i = 0; i < v.size(); i += 2) {
      sum += v[i];
    }
    cout << sum << "\n";
  }
  return 0;
}
