#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 20, MAXM = 15e4 + 20, MOD = 1000 * 1000 * 1000 + 7;
int a[MAXN];
void solve() {
  string s;
  cin >> s;
  bool one = 0;
  int cnt = 0;
  s += '0';
  vector<int> vec;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      cnt++;
      one = 1;
    } else if (one) {
      vec.push_back(cnt);
      one = 0;
      cnt = 0;
    }
  }
  sort(vec.rbegin(), vec.rend());
  int ans = 0;
  for (int i = 0; i < vec.size(); i += 2) {
    ans += vec[i];
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) solve();
}
