#include <bits/stdc++.h>
int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  int t, x, i, j, c;
  scanf("%d", &t);
  while (t--) {
    char n[101];
    int m[101];
    scanf("%s", &n);
    x = strlen(n);
    j = 0;
    c = 0;
    for (i = 0; i < x; i++) {
      if (n[i] == '1')
        c++;
      else if (c > 0) {
        m[j++] = c;
        c = 0;
      }
    }
    if (c > 0) m[j++] = c;
    qsort(m, j, sizeof(int), cmpfunc);
    c = 0;
    for (i = j - 1; i >= 0; i = i - 2) c = c + m[i];
    printf("%d\n", c);
  }
}
