#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int p = 0;
    if (s[0] == '1' && s.size() == 1) {
      cout << "1\n";
      continue;
    }
    vector<int> q;
    if (s[0] == '1') p++;
    char ch = s[0];
    int y = s.size();
    for (int i = 1; i < s.size(); i++) {
      if (ch == s[i] && s[i] == '1')
        p++;
      else if (s[i] == '1')
        p = 1;
      else {
        if (p) q.push_back(p);
        p = 0;
      }
      if (i == y - 1 && p) q.push_back(p);
      ch = s[i];
    }
    sort(q.begin(), q.end(), greater<int>());
    int sum = 0;
    for (int i = 0; i < q.size(); i += 2) sum += q[i];
    cout << sum << "\n";
  }
  return 0;
}
