#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    string s;
    cin >> s;
    priority_queue<int> a;
    int seq = 0;
    for (int i = 0; i < (int)s.size(); i++) {
      if (s[i] == '1')
        seq++;
      else {
        if (seq > 0) a.push(seq);
        seq = 0;
      }
    }
    if (seq > 0) a.push(seq);
    seq = 0;
    int ans = 0;
    while (!a.empty()) {
      ans += a.top();
      a.pop();
      if (!a.empty()) a.pop();
    }
    printf("%d\n", ans);
  }
  return 0;
}
