#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  long long A, B, C, D, E, F, N, K, M, Z, sum = 0, num = 0, flag = 0;
  string S, T;
  cin >> Z;
  queue<long long> que;
  while (Z--) {
    cin >> S;
    vector<long long> P(0, 0);
    num = 0;
    S += '0';
    for (long long int i = 0; i < S.size(); i++) {
      if (S[i] == '1')
        num++;
      else {
        P.push_back(num);
        num = 0;
      }
    }
    sort(P.begin(), P.end());
    reverse(P.begin(), P.end());
    sum = 0;
    for (long long int i = 0; i < P.size(); i++) {
      sum += P[i];
      i++;
    }
    que.push(sum);
  }
  while (!que.empty()) {
    cout << que.front() << endl;
    que.pop();
  }
}
