#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int kase;
  cin >> kase;
  while (kase--) {
    vector<int> ans;
    string str;
    cin >> str;
    int cnt = 1;
    for (int i = 0; i < str.length() - 1; ++i) {
      int cnt = 1;
      if (str[i] == '1') {
        int pos = i;
        bool flag = false;
        while (str[i] == str[i + 1]) {
          flag = true;
          str.erase(i, 1);
          cnt++;
        }
        if (flag) str[pos] = '0';
      }
      if (cnt > 1) ans.push_back(cnt);
    }
    for (int i = 0; i < str.length(); i++) {
      if (str[i] == '1') {
        str[i] = '0';
        ans.push_back(1);
      }
    }
    sort(ans.rbegin(), ans.rend());
    int res = 0;
    for (int i = 0; i < ans.size(); i += 2) res += ans[i];
    cout << res << endl;
  }
  return 0;
}
