#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int count = 0;
    priority_queue<int, vector<int>> pq;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        count++;
      } else {
        pq.push(count);
        count = 0;
      }
    }
    if (count != 0) {
      pq.push(count);
      count = 0;
    }
    bool temp = false;
    while (!pq.empty()) {
      int x = pq.top();
      pq.pop();
      if (!temp) {
        count += x;
      }
      temp = !temp;
    }
    cout << count << endl;
  }
  return 0;
}
