#include <bits/stdc++.h>
using std::string;
using std::vector;
template <typename T>
T read() {
  T var;
  std::cin >> var;
  return var;
}
void solve() {
  string str = read<string>();
  vector<int> segments;
  int n = str.length();
  for (int i = 0; i < n;) {
    if (str[i] == '0') {
      i++;
    } else {
      int j = i;
      while (j < n && str[j] == '1') {
        j++;
      }
      segments.push_back(j - i);
      i = j;
    }
  }
  std::sort(segments.begin(), segments.end(), std::greater<int>());
  int answer = 0;
  int sn = segments.size();
  for (int i = 0; i < sn; i++) {
    if (i % 2 == 0) {
      answer += segments[i];
    }
  }
  std::cout << answer << "\n";
}
int main() {
  int t = read<int>();
  while (t--) {
    solve();
  }
  return EXIT_SUCCESS;
}
