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