#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long testcases;
  cin >> testcases;
  while (testcases--) {
    string s;
    cin >> s;
    vector<long long> v;
    long long f = 0;
    for (__typeof(0) i = 0; i <= s.size() - 1; i++) {
      if (s[i] == '1')
        f++;
      else if (f != 0) {
        v.push_back(f);
        f = 0;
      }
    }
    if (f != 0) v.push_back(f);
    long long ans = 0;
    sort(v.begin(), v.end(), greater<long long>());
    for (long long i = 0; i < v.size(); i += 2) {
      ans += v[i];
    }
    cout << ans << "\n";
  }
  return 0;
}
