#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(nullptr);
  int T, i, len, cnt, j;
  vector<int> v;
  string s;
  cin >> T;
  while (T--) {
    cin >> s;
    len = s.size();
    cnt = 1;
    for (i = 0; i < len; i++) {
      if (s[i] == '1') {
        cnt = 0;
        for (j = i; j < len; j++) {
          if (s[j] == '0' || j == len - 1) {
            if (s[j] == '1') cnt++;
            v.push_back(cnt);
            i = j;
            break;
          }
          cnt++;
        }
      }
    }
    int sum = 0;
    sort(v.rbegin(), v.rend());
    for (i = 0; i < v.size(); i += 2) sum += v[i];
    cout << sum << '\n';
    v.clear();
  }
  return 0;
}
