#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    int c = 0, res = 0;
    vector<int> v;
    int i = 0;
    while (i < n) {
      if (s[i] == '1') {
        c = 0;
        while (s[i] == '1' && i < n) {
          c++;
          i++;
        }
        v.push_back(c);
      } else {
        while (s[i] == '0' && i < n) {
          i++;
        }
      }
    }
    sort(v.begin(), v.end());
    int p = v.size();
    int j = p - 1;
    while (p != 0 && j > -1) {
      res += v[j];
      j--;
      j--;
    }
    cout << res << endl;
  }
  return 0;
}
