#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int main() {
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    vector<int> A;
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] == '1') {
        if (i == 0 || s[i - 1] == '0')
          A.push_back(1);
        else if (s[i - 1] == '1')
          A[A.size() - 1]++;
      }
    }
    sort(A.begin(), A.end(), greater<int>());
    int ans = 0;
    for (int i = 0; i < A.size(); ++i) {
      if (i % 2 == 0) ans += A[i];
    }
    cout << ans << endl;
  }
  return 0;
}
