#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream &operator<<(ostream &out, const vector<A> &a) {
  for (const A &it : a) out << it << " ";
  return out;
}
template <class A, class B>
istream &operator>>(istream &in, pair<A, B> &a) {
  return in >> a.first >> a.second;
}
template <class A>
istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a) in >> i;
  return in;
}
ifstream cinn("in.txt");
ofstream coutt("out.txt");
long long poww(const long long &a, long long b,
               const long long &m = 1000000007) {
  if (b == 0) return 1;
  long long first = poww(a, b / 2, m);
  first = first * first % m;
  if (b & 1) first = first * a % m;
  return first;
}
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b % a, a);
}
bool mod(long double a, long double b) { return a / b - floor(a / b); }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long i, j, first, t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<long long> v;
    long long n = s.length();
    long long cur = 0, len = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '0') {
        if (cur == 1) {
          v.push_back(len);
        }
        len = 0;
      } else {
        len++;
      }
      cur = s[i] - '0';
    }
    if (len > 0) v.push_back(len);
    sort((v).rbegin(), (v).rend());
    long long ans = 0;
    for (i = 0; i < v.size(); i++) {
      if (i % 2 == 0) {
        ans += v[i];
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
