#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
class DisjointSet {
 public:
  vector<ll> rank, p, siz;
  DisjointSet() {}
  DisjointSet(ll size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    siz.resize(size, 1);
    for (int i = (int)(0); i < (int)(size); i++) makeSet(i);
  }
  void makeSet(ll x) {
    p[x] = x;
    rank[x] = 0;
  }
  bool same(ll x, ll y) { return root(x) == root(y); }
  void unite(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (rank[x] > rank[y]) {
      siz[x] += siz[y];
      p[y] = x;
    } else {
      siz[y] += siz[x];
      p[x] = y;
      if (rank[x] == rank[y]) rank[y]++;
    }
  }
  ll root(ll x) {
    if (x != p[x]) {
      p[x] = root(p[x]);
    }
    return p[x];
  }
  ll size(ll x) { return siz[root(x)]; }
};
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int k = 0;
    int ans = 0;
    while (1) {
      int cnt = 0;
      int now = 0;
      int maxcnt = 0;
      int n = s.size();
      for (int i = (int)(0); i < (int)(n); i++) {
        if (s[i] == '1')
          cnt++;
        else {
          if (maxcnt < cnt) {
            maxcnt = cnt;
            now = i - 1;
          }
          cnt = 0;
        }
      }
      if (maxcnt < cnt) {
        now = n - 1;
        maxcnt = cnt;
      }
      if (maxcnt == 0) break;
      if (k % 2 == 0) ans += maxcnt;
      s.erase(now - maxcnt + 1, maxcnt);
      k = 1 - k;
    }
    cout << ans << endl;
  }
}
