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