#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int arr[MAXN];
vector<int> v1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    v1.clear();
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') {
        int j = i + 1;
        while (j < n && s[j] == '1') {
          j++;
        }
        v1.push_back(j - i);
        i = j - 1;
      }
    }
    sort(v1.rbegin(), v1.rend());
    int ans = 0;
    for (int i = 0; i < v1.size(); i += 2) {
      ans += v1[i];
    }
    cout << ans << endl;
  }
}
