#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void solve() {
  string s;
  cin >> s;
  vector<int> arr;
  int ones = 0;
  for (char c : s) {
    if (c == '1')
      ones++;
    else {
      if (ones) arr.push_back(ones);
      ones = 0;
    }
  }
  if (ones) arr.push_back(ones);
  if (arr.empty()) {
    cout << 0 << endl;
    return;
  }
  sort(arr.begin(), arr.end());
  int score = 0;
  while (!arr.empty()) {
    score += arr.back();
    arr.pop_back();
    if (!arr.empty()) arr.pop_back();
  }
  cout << score << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
