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