#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    vector<int> v;
    int i = 0;
    int j = 0;
    while (i < n) {
      while (i < n && s[i] == '0') {
        i++;
      }
      if (i > n) break;
      j = i;
      while (j < n && s[j] == '1') {
        j++;
      }
      if (j - i > 0) v.push_back(j - i);
      i = j;
    }
    sort(v.begin(), v.end());
    int cnt = 0;
    int flag = 1;
    for (int i = v.size() - 1; i >= 0; i--) {
      if (flag == 1) {
        flag = 0;
        cnt += v[i];
      } else {
        flag = 1;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
