#include <bits/stdc++.h>
int ans(std::string game) {
  int count = 0;
  int alcie = 0;
  std::vector<int> x;
  int size = game.length();
  for (int i = 0; i < size; i++) {
    if (game[i] == '1') {
      count++;
      if (i == size - 1) {
        x.push_back(count);
      }
    } else if (game[i] == '0' && count != 0) {
      x.push_back(count);
      count = 0;
    }
  }
  std::sort(x.begin(), x.end(), std::greater<int>());
  size = x.size();
  for (int i = 0; i < size; i++) {
    if (i % 2 == 0) alcie += x[i];
  }
  return alcie;
}
int main() {
  std::ios_base::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
  int t;
  std::cin >> t;
  std::string game;
  for (int i = 0; i < t; i++) {
    std::cin >> game;
    std::cout << ans(game) << "\n";
  }
  return 0;
}
