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