#include <bits/stdc++.h>
using namespace std;
bool compare(const pair<int, int> &i, const pair<int, int> &j) {
  return (i.second == j.second) ? (i.first < j.first) : (i.second < j.second);
}
const long long mod = 1e9 + 7;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    s += '0';
    long long m = 0;
    std::vector<int> ans;
    for (int i = (0); i < (s.size()); i++) {
      if (s[i] == '1')
        m++;
      else {
        if (m != 0) ans.push_back(m);
        m = 0;
      }
    }
    sort(ans.begin(), ans.end());
    long long res = 0;
    for (int i = ans.size() - 1; i >= 0; i = i - 2) {
      res += ans[i];
    }
    cout << res << "\n";
  }
}
