#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<int> counts;
    int current_count = 0;
    for (char c : s) {
      if (c == '1') {
        current_count += 1;
      } else if (current_count != 0) {
        counts.emplace_back(current_count);
        current_count = 0;
      }
    }
    if (current_count != 0) {
      counts.emplace_back(current_count);
    }
    sort(counts.begin(), counts.end());
    int n = counts.size();
    int score = 0;
    for (int i = 1 - (n % 2); i < n; i += 2) {
      score += counts[i];
    }
    cout << score << '\n';
  }
  return 0;
}
