#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
void solve() {
  string s;
  cin >> s;
  s.push_back('0');
  vector<int> a;
  int cc = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == '1')
      cc++;
    else {
      a.push_back(cc);
      cc = 0;
    }
  }
  sort(a.rbegin(), a.rend());
  int total = 0;
  for (int i = 0; i < (int)a.size(); i++) {
    if (i % 2 == 0) total += a[i];
  }
  cout << total << "\n";
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
