#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, m, i, j, z, k, q, sum, maxm, minm, flag, counter;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    n = s.length();
    vector<long long> v;
    counter = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '1') {
        counter++;
      }
      if (s[i] == '0' || i == n - 1) {
        v.push_back(counter);
        counter = 0;
      }
    }
    sort(v.begin(), v.end());
    sum = 0;
    for (i = v.size() - 1; i >= 0; i = i - 2) {
      sum += v[i];
    }
    cout << sum << endl;
  }
  return 0;
}
