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