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