#include <bits/stdc++.h>
using namespace std;
using namespace std;
const long long int mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<int> v;
    int flag = 0;
    int l = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1' && flag == 0) {
        flag = 1;
        l = i;
      } else if (s[i] == '0' && flag == 1) {
        flag = 0;
        v.push_back(i - l);
      }
    }
    if (flag == 1) {
      v.push_back(s.size() - l);
    }
    sort(v.rbegin(), v.rend());
    int count = 0;
    for (int i = 0; i < v.size(); i += 2) {
      count += v[i];
    }
    cout << count << '\n';
  }
  return 0;
}
