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