#include <bits/stdc++.h>
using namespace std;
void fast_IO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const long long INF = 1e18;
const long long DEBUG = 1;
long long n;
string s;
vector<long long> a;
void init() {
  cin >> s;
  n = s.size();
  a.clear();
  long long cnt = 0;
  for (long long i = 0; i < n; ++i) {
    if (s[i] == '1') {
      cnt++;
    }
    if (s[i] == '0') {
      if (cnt != 0) {
        a.push_back(cnt);
        cnt = 0;
      }
    }
  }
  a.push_back(cnt);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
}
signed main() {
  long long q = 1;
  cin >> q;
  for (long long qq = 0; qq < q; ++qq) {
    init();
    long long ans = 0;
    for (long long i = 0; i < a.size(); i += 2) {
      ans += a[i];
    }
    cout << ans << endl;
  }
  return 0;
}
