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