#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    int count = 0, n = str.length();
    vector<int> v;
    for (int i = 0; i < n; i++) {
      if (str[i] == '1')
        count++;
      else if ((str[i - 1] == '1' && str[i] == '0')) {
        v.push_back(count);
        count = 0;
      }
      if (i == n - 1) v.push_back(count);
    }
    sort(v.begin(), v.end());
    int A_score = 0;
    for (int i = v.size() - 1; i >= 0; i -= 2) A_score += v[i];
    cout << A_score << '\n';
  }
  return 0;
}
