#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int ttt;
  cin >> ttt;
  while (ttt--) {
    string s;
    cin >> s;
    long long int n = (long long int)s.size(), c = 0, ans = 0;
    vector<long long int> v;
    for (long long int i = 0; i <= n - 1; i++) {
      if (s[i] == '1')
        c++;
      else {
        if (c != 0) v.push_back(c);
        c = 0;
      }
    }
    if (c != 0) v.push_back(c);
    sort(v.begin(), v.end());
    for (long long int i = (long long int)v.size() - 1; i >= 0; i -= 2)
      ans += v[i];
    cout << ans << "\n";
  }
}
