#include <bits/stdc++.h>
using namespace std;
template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& input) {
  for (auto const& i : input) {
    os << i << " ";
  }
  return os;
}
template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& input) {
  for (auto const& i : input) {
    os << i << " ";
  }
  return os;
}
template <class T, size_t n>
std::ostream& operator<<(std::ostream& os, const std::array<T, n>& input) {
  for (size_t i = 0; i < n; ++i) {
    os << input[i] << " ";
  }
  return os;
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& input) {
  os << "(" << input.first << ", " << input.second << ')';
  return os;
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& os,
                         const std::unordered_map<T1, T2>& input) {
  for (auto const& i : input) {
    os << i << " ";
  }
  return os;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
double startTime;
double getCurrentTime() {
  return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int maxn = 50;
void solve() {
  string s;
  cin >> s;
  int n = int((s).size());
  int cnt = 0;
  vector<int> a(0);
  for (int i = 0; i < int(n); ++i) {
    if (s[i] == '0') {
      if (cnt) a.push_back(cnt);
      cnt = 0;
    } else {
      cnt++;
    }
  }
  if (cnt) a.push_back(cnt);
  sort(a.begin(), a.end());
  int sum = 0, sum1 = 0;
  for (int i = 0; i < int(int((a).size())); ++i) {
    sum += a[i];
    if (i & 1) sum1 += a[i];
  }
  cout << max(sum1, sum - sum1) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int cas = 1;
  cin >> cas;
  for (int ca = 0; ca < int(cas); ++ca) solve();
  return 0;
}
