#include <bits/stdc++.h>
using namespace std;
long long int arr[100005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, cnt = 0;
    vector<long long int> v;
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') cnt++;
      if (s[i] == '0') {
        v.push_back(cnt);
        cnt = 0;
      }
    }
    v.push_back(cnt);
    sort(v.begin(), v.end());
    long long int a = 0, b = 0;
    for (int i = 0; i < v.size(); i++) {
      if (i % 2 == 0)
        a += v[i];
      else
        b += v[i];
    }
    if (a > b)
      cout << a << "\n";
    else
      cout << b << "\n";
  }
  return 0;
}
