#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<long long> num;
    long long len = s.size();
    for (long long i = 0; i < len; i++) {
      if (s[i] == '1') {
        long long now = 0;
        while (i < len && s[i] == '1') now++, i++;
        num.push_back(now);
      }
    }
    sort(num.begin(), num.end());
    long long ans = 0;
    for (long long i = (long long)num.size() - 1; i >= 0; i -= 2) ans += num[i];
    cout << ans << endl;
  }
}
