#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int MAX = 1e5 + 5;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int sz = s.size();
    s += s;
    vector<int> ones;
    int cnt = 0;
    for (int i = 0; i < sz; i++) {
      if (s[i] == '1') {
        cnt++;
        if (s[i + 1] != '1' || i + 1 == sz) {
          ones.push_back(cnt);
          cnt = 0;
        }
      }
    }
    sort(ones.begin(), ones.end(), greater<int>());
    int ans = 0;
    for (int i = 0; i < ones.size(); i += 2) {
      ans += ones[i];
    }
    cout << ans << endl;
  }
}
