#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
double pi = 3.1415926535;
long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long int power(long long int a, long long int n) {
  long long int res = 1;
  while (n) {
    if (n % 2) {
      res = res * a;
    }
    n = n / 2;
    a = a * a;
  }
  return res;
}
bool checkprime(long long int n) {
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long int mpow(long long int a, long long int n) {
  long long int res = 1;
  while (n) {
    if (n % 2) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    n = n / 2;
  }
  return res;
}
void solve() {
  string s;
  cin >> s;
  map<int, int> mp;
  int n = s.size();
  int cnt = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cnt = 0;
    while (i < n && s[i] == '1') {
      i++;
      cnt++;
    }
    v.push_back(cnt);
  }
  int a[101] = {0}, ans = 0;
  bool f = true;
  sort(v.begin(), v.end(), greater<int>());
  for (auto c : v) {
    if (f) {
      ans += c;
      f = false;
    } else {
      f = true;
    }
  }
  cout << ans << endl;
}
int main() {
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
