#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string s;
    cin >> s;
    int b = 0;
    int j = 1;
    int k = 0;
    while (k != s.length()) {
      k = 0;
      int max = -1;
      int e = 0, r = 0;
      for (int i = 0; i < s.length(); i++) {
        int q = 0, w = 0;
        q = i;
        while (s[i] == '1' && q < s.length()) {
          i++;
        }
        w = i;
        if ((w - q) > max) {
          e = q;
          r = w;
          max = w - q;
        }
      }
      for (int i = 0; i < s.length(); i++) {
        if (i >= e && i <= r) {
          s[i] = '0';
        }
        if (s[i] == '0') {
          k++;
        }
      }
      if (j % 2 == 1) {
        b = b + (r - e);
      }
      j++;
    }
    cout << b << endl;
  }
  return 0;
}
