#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<int> v;
    for (int i = 0; i < s.size(); i++) {
      int c = 0;
      if (s[i] == '1') {
        c++;
        int j = i + 1;
        while (s[j] == '1') {
          c++;
          j++;
        }
        v.push_back(c);
        i = j;
      }
    }
    sort(v.begin(), v.end());
    int c = 0;
    for (int i = v.size() - 1; i >= 0; i -= 2) {
      c += v[i];
    }
    cout << c << endl;
  }
}
