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