#include <bits/stdc++.h>
using namespace std;
int main() {
  int testCase;
  cin >> testCase;
  while (testCase--) {
    string s;
    cin >> s;
    int streak = 0, ans = 0;
    vector<int> v;
    for (int i = 0; i < s.size(); i++) {
      if (streak > 0 && s[i] == '0') {
        v.push_back(streak);
        streak = 0;
      } else if (s[i] == '1')
        streak++;
    }
    if (streak > 0) v.push_back(streak);
    sort(v.rbegin(), v.rend());
    for (int i = 0; i < v.size(); i += 2) {
      ans += v[i];
    }
    cout << ans << endl;
  }
  return 0;
}
