#include <bits/stdc++.h>
using namespace std;
int main() {
  long long tc, n, i, o, l, j;
  string s;
  cin >> tc;
  while (tc--) {
    long long one = 0;
    vector<long long> v;
    cin >> s;
    getchar();
    s = s + '0';
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        one++;
      } else {
        if (one >= 1) {
          v.push_back(one);
          one = 0;
        }
      }
    }
    cout << endl;
    if (v.size() == 0) {
      cout << "0" << endl;
    } else {
      sort(v.begin(), v.end(), greater<long long>());
      long long alice = 0;
      for (i = 0; i < v.size(); i += 2) {
        alice += v[i];
      }
      cout << alice << endl;
    }
    v.clear();
  }
  return 0;
}
