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