#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<int> cnts;
    int i = 0;
    while (i < s.length()) {
      int cnt = 0;
      if (s[i] == '0') {
        i++;
      }
      while (i < s.length() && s[i] == '1') {
        cnt++;
        i++;
      }
      cnts.push_back(cnt);
    }
    sort(cnts.begin(), cnts.end());
    int a = 1;
    int alice = 0;
    for (int i = cnts.size() - 1; i >= 0; i--) {
      if (a > 0) alice += cnts[i];
      a = -1 * a;
    }
    cout << alice << endl;
  }
}
