#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  long long int n = s.size(), i, j;
  vector<long long int> a(n, 0), res;
  a[0] = s[0] - '0';
  for (i = 1; i < n; i++) {
    if (s[i] == '1') a[i] = (s[i] - '0') + a[i - 1];
  }
  for (i = 1; i < n; i++) {
    if (!a[i] and a[i - 1]) {
      res.push_back(a[i - 1]);
    }
  }
  if (a[n - 1]) res.push_back(a[n - 1]);
  sort(res.begin(), res.end(), greater<long long int>());
  long long int score = 0;
  for (i = 0; i < res.size(); i += 2) {
    score += res[i];
  }
  cout << score << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
