#include <bits/stdc++.h>
using namespace std;
string tostr(long long a) {
  stringstream rr;
  rr << a;
  return rr.str();
}
long long pow(long long c, long long d) { return d == 0 ?: c * pow(c, d - 1); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t, z = 0;
  cin >> t;
  while (t--) {
    long long n, m, k = 0, i, j, x, y, p = 0, s = 0, h, f = 0;
    string a;
    cin >> a;
    vector<long long> v;
    if (a[0] == '1') {
      k = 1;
    }
    for (i = 1; i < a.size(); i++) {
      if (a[i] == '1')
        k++;
      else {
        if (k > 0) {
          v.push_back(k);
        }
        k = 0;
      }
    }
    if (k > 0) {
      v.push_back(k);
    }
    if (v.size() >= 1) {
      sort(v.begin(), v.end());
      for (i = v.size() - 1; i >= 0; i -= 2) {
        s += v[i];
      }
    }
    cout << s << endl;
  }
  return 0;
}
