#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int c = 0, l = 0;
    string s;
    cin >> s;
    s = s + '0';
    vector<int> a;
    for (int i = 0; i < (int)s.length(); i++) {
      if (s[i] == '1') {
        c++;
      } else {
        a.push_back(c);
        c = 0;
        l++;
      }
    }
    sort(a.begin(), a.end(), greater<int>());
    int ans = 0;
    for (int i = 0; i < l; i += 2) {
      ans += a[i];
    }
    cout << ans << "\n";
  }
}
