#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> count;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      cnt++;
    else {
      if (cnt > 0) {
        count.push_back(cnt);
        cnt = 0;
      }
    }
  }
  if (cnt > 0) {
    count.push_back(cnt);
  }
  sort(count.begin(), count.end(), greater<int>());
  int ans = 0;
  for (int i = 0; i < count.size(); i += 2) {
    ans = ans + count[i];
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
