#include <bits/stdc++.h>
using namespace std;
const int S = 1 * 100 * 2000 + 5;
const long long int INF = 2e18 + 5;
const int MOD = 998244353;
const long double EPS = 0.00000000001;
const int ENC = 1024 * 8;
const bool LOCAL = false;
const int NONE = -42;
template <typename T>
struct base_point {
  T x, y;
  base_point<T>() {}
  base_point<T>(T x, T y) {
    this->x = x;
    this->y = y;
  }
  void read() { cin >> x >> y; }
  pair<T, T> as_pair() { return make_pair(x, y); }
  base_point<T> operator+(base_point<T> &other) {
    return base_point<T>(x + other.x, y + other.y);
  }
  base_point<T> operator+(base_point<T> &&other) {
    return base_point<T>(x + other.x, y + other.y);
  }
  base_point<T> operator-(base_point<T> &other) {
    return base_point<T>(x - other.x, y - other.y);
  }
  base_point<T> operator-(base_point<T> &&other) {
    return base_point<T>(x - other.x, y - other.y);
  }
  base_point<T> operator*(T scalar) {
    return base_point<T>(x * scalar, y * scalar);
  }
  base_point<T> rotate90() { return base_point<T>(-y, x); }
  base_point<T> rotate(T angle) {
    return base_point<T>(cosl(angle) * x - sinl(angle) * y,
                         cosl(angle) * y + sinl(angle) * x);
  }
  bool in_first_quadrant() { return (x >= 0 && y > 0); }
  T operator*(base_point<T> &other) { return x * other.x + y * other.y; }
  T operator%(base_point<T> &other) { return x * other.y - y * other.x; }
  T operator%(base_point<T> &&other) { return x * other.y - y * other.x; }
  bool operator<(base_point<T> &other) {
    if (x == other.x) return y < other.y;
    return x < other.x;
  }
  bool operator==(base_point<T> &other) {
    return (x == other.x) && (y == other.y);
  }
  bool operator==(base_point<T> &&other) {
    return (x == other.x) && (y == other.y);
  }
  bool operator!=(base_point<T> &other) {
    return (x != other.x) || (y != other.y);
  }
  bool operator!=(base_point<T> &&other) {
    return (x != other.x) || (y != other.y);
  }
  T norm() { return x * x + y * y; }
  T len() { return sqrtl(norm()); }
};
mt19937 mt_rand(time(0));
struct mre {
  int v;
  mre() { v = 0; }
  mre(int nv) { v = nv % MOD; }
  mre(long long int nv) { v = nv % MOD; }
  mre operator+(mre other) {
    int r = (v + other.v) % MOD;
    return mre(r);
  }
  mre operator-(mre other) { return mre(v) + other.neg(); }
  mre operator*(mre other) {
    int r = (v * (long long int)other.v) % MOD;
    return mre(r);
  }
  mre neg() {
    if (v == 0) return mre(0);
    return mre(MOD - v);
  }
  bool operator==(mre &other) { return v == other.v; }
  bool operator==(mre &&other) { return v == other.v; }
  mre bpow(int e) {
    if (e == 0) return mre(1);
    mre sq = mre(v) * mre(v);
    if (e & 1) {
      return sq.bpow(e / 2) * mre(v);
    } else {
      return sq.bpow(e / 2);
    }
  }
  mre inv() { return mre(v).bpow(MOD - 2); }
  bool operator<(const mre &other) { return v < other.v; }
};
void fail() {
  cout << "No" << endl;
  exit(0);
}
mre fact[2][S];
long long int a[S];
void prepare_fact() {
  fact[0][0] = mre(1);
  for (int i = 0; i < (S - 1); i++) fact[0][i + 1] = fact[0][i] * mre(i + 1);
  int last = S - 1;
  fact[1][last] = fact[0][last].inv();
  for (int i = last - 1; i >= 0; i--) fact[1][i] = fact[1][i + 1] * mre(i + 1);
}
void solvet() {
  string s;
  cin >> s;
  s.push_back('0');
  int n = s.size();
  int cso = 0;
  vector<int> tokens;
  for (auto c : s) {
    if (c == '1') {
      cso++;
    } else {
      tokens.push_back(cso);
      cso = 0;
    }
  }
  sort(tokens.begin(), tokens.end());
  reverse(tokens.begin(), tokens.end());
  int ans = 0;
  for (int i = 0; i < tokens.size(); i += 2) {
    ans += tokens[i];
  }
  cout << ans << endl;
}
void solve() {
  int tq = 1;
  cin >> tq;
  for (int tqc = 0; tqc < (tq); tqc++) solvet();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout.precision(20);
  solve();
}
