#include <bits/stdc++.h>
using namespace std;
int maxi, maxj;
string str;
void solve() {
  int ans = 0;
  int i = 0, j = 0;
  int n = (int)(str).size();
  while (j < n) {
    if (str[i] == '0') {
      i++;
      j++;
      continue;
    }
    while (str[j + 1] == str[i]) {
      j++;
    }
    if (ans < j - i + 1) {
      ans = j - i + 1;
      maxj = j;
      maxi = i;
    }
    j++;
    i = j;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> str;
    int ocnt = 0;
    for (auto x : str) {
      if (x == '1') ocnt++;
    }
    int flag = 1;
    int ans = 0;
    while (ocnt > 0) {
      solve();
      int val = maxj - maxi + 1;
      if (flag) {
        ans += val;
        flag = 0;
      } else {
        flag = 1;
      }
      str.erase(maxi, maxj - maxi + 1);
      ocnt -= val;
    }
    cout << ans << endl;
  }
  return 0;
}
