#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 10e4 + 5;
int a[N];
int b[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    string n;
    cin >> n;
    int k = 1;
    b[0] = 0;
    for (int i = 0; i < n.size(); i++) {
      if (n[i] == '0') b[k++] = i + 1;
    }
    b[k++] = n.size() + 1;
    int m = 0;
    for (int i = 0; i < k - 1; i++) {
      a[m++] = b[i + 1] - b[i] - 1;
    }
    sort(a, a + m);
    int sum = 0;
    for (int i = m - 1; i >= 0; i = i - 2) {
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}
