#include <bits/stdc++.h>
using namespace std;
void solve();
int main() { solve(); }
void solve() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    priority_queue<int> q;
    int k = s.length();
    int cur = (s[0] == '1') ? 1 : 0;
    for (int i = 1; i < k; i++) {
      if (s[i] == '1' && s[i - 1] == '0') {
        cur = 1;
      }
      if (s[i] == '1' && s[i - 1] == '1') {
        cur++;
      }
      if (s[i] == '0') {
        if (cur != 0) {
          q.push(cur);
          cur = 0;
        }
      }
    }
    if (s[k - 1] == '1') {
      if (cur != 0) {
        q.push(cur);
        cur = 0;
      }
    }
    int ans = 0;
    int qs = q.size();
    for (int i = 0; i < qs; i++) {
      if ((i & 0x1) == 0) {
        ans += q.top();
      } else {
      }
      q.pop();
    }
    cout << ans << endl;
  }
}
