#include <bits/stdc++.h>
using namespace std;
const int_fast32_t inf = 1e9 + 7;
const int_fast32_t MOD = 1000000007;
const int_fast64_t llinf = 1e18;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int_fast32_t t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int_fast32_t n = s.size();
    vector<pair<int_fast32_t, int_fast32_t> > v;
    int_fast32_t pre = s[0] - '0';
    int_fast32_t cnt = 1;
    for (int_fast64_t i = (1); i < (n); i++) {
      if (s[i] - '0' != pre) {
        v.emplace_back(cnt, pre);
        pre = s[i] - '0';
        cnt = 0;
      }
      ++cnt;
    }
    v.emplace_back(cnt, pre);
    vector<int_fast32_t> v2;
    for (auto p : v) {
      if (p.second == 1) v2.push_back(p.first);
    }
    sort(v2.rbegin(), v2.rend());
    int_fast32_t ans = 0;
    for (int_fast32_t i = 0; i < v2.size(); i += 2) ans += v2[i];
    cout << (ans) << "\n";
  }
  return 0;
}
