#include <bits/stdc++.h>
using namespace std;
bool compare(const int a, const int b) {
  if (a <= b) {
    return false;
  }
  return true;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string s;
    cin >> s;
    int last_count = 0;
    vector<int> arr;
    for (int j = 0; j < s.length(); j++) {
      if (j == 0) {
        if (s[0] == '1') {
          last_count++;
        }
      } else {
        if (s[j] == '0') {
          if (last_count != 0) {
            arr.push_back(last_count);
          }
          last_count = 0;
        } else {
          last_count++;
        }
      }
    }
    if (last_count != 0) {
      arr.push_back(last_count);
    }
    if (arr.size() == 0) {
      cout << 0 << endl;
    } else {
      sort(arr.begin(), arr.end(), compare);
      int alice_Count = 0;
      for (int j = 0; j < arr.size(); j++) {
        if (j % 2 == 0) {
          alice_Count += arr[j];
        }
      }
      cout << alice_Count << endl;
    }
  }
  return 0;
}
