#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<int> ar;
    int c = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        c++;
      } else {
        if (c != 0) ar.push_back(c);
        c = 0;
      }
    }
    if (c != 0) ar.push_back(c);
    sort(ar.rbegin(), ar.rend());
    int res = 0;
    for (int i = 0; i < ar.size(); i += 2) {
      res += ar[i];
    }
    cout << res << "\n";
  }
}
