#include <bits/stdc++.h>
using namespace std;
string second;
long long n, m, x, y, z, d, k, l, r;
long long a[500005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long ans = 0;
    cin >> second;
    vector<long long> groups;
    int cnt = 0;
    for (int i = 0; second[i]; i++) {
      if (second[i] == '1') {
        cnt++;
      } else {
        if (cnt > 0) {
          groups.push_back(cnt);
          cnt = 0;
        }
      }
    }
    if (cnt > 0) {
      groups.push_back(cnt);
      cnt = 0;
    }
    sort(groups.rbegin(), groups.rend());
    for (int i = 0; i < groups.size(); i += 2) {
      ans += groups[i];
    }
    cout << ans << "\n";
  }
  return 0;
}
