#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int cnt = 0;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        cnt++;
      } else {
        if (cnt > 0) {
          v.push_back(cnt);
        }
        cnt = 0;
      }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
      if (s[i] == 1) {
        cnt++;
      } else {
        if (cnt > 0) {
          v.push_back(cnt);
        }
        break;
      }
    }
    sort(v.begin(), v.end());
    if (v.size() % 2 == 0) {
      int sum = 0;
      for (int i = 1; i < v.size(); i += 2) {
        sum += v[i];
      }
      cout << sum << endl;
    } else {
      int sum = 0;
      for (int i = 0; i < v.size(); i += 2) {
        sum += v[i];
      }
      cout << sum << endl;
    }
    v.clear();
  }
  return 0;
}
