#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
struct point {
  int x, y;
};
void solve() {
  string s;
  cin >> s;
  vector<int> res;
  int cur = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      cur++;
    } else {
      if (cur) res.push_back(cur);
      cur = 0;
    }
  }
  if (cur) res.push_back(cur);
  sort(res.rbegin(), res.rend());
  int ans = 0;
  for (int i = 0; i < res.size(); i += 2) {
    ans += res[i];
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    solve();
    cout << '\n';
  }
}
