#include <bits/stdc++.h>
using namespace std;
const int N = 100007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> chunks;
    for (int i = 0; i < n;) {
      int cnt = 0;
      if (s[i] == '1') {
        while (s[i] != '0' and i < n) {
          cnt++;
          i++;
        }
        chunks.push_back(cnt);
      } else
        i++;
    }
    sort((chunks).begin(), (chunks).end());
    reverse((chunks).begin(), (chunks).end());
    int ans = 0;
    for (int i = 0; i < chunks.size(); i++) {
      if (!(i & 1)) ans += chunks[i];
    }
    cout << ans << "\n";
  }
  return 0;
}
