#include <bits/stdc++.h>
void sort0(int *arr, int n) {
  int i, j, min, min_index;
  for (i = 0; i < n; i++) {
    min = arr[i], min_index = i;
    for (j = i; j < n; j++) {
      if (arr[j] < min) {
        min = arr[j];
        min_index = j;
      }
    }
    arr[min_index] = arr[i];
    arr[i] = min;
  }
}
int main() {
  int t, len, x, ALICE;
  char *s;
  int arr[50];
  scanf("%d", &t);
  while (t > 0) {
    s = (char *)malloc(4000);
    ALICE = 0, len = 0;
    scanf("%s", s);
    while (*s != 0) {
      if (*s == '1') {
        x = 0;
        while (*s == '1') {
          s++;
          x++;
        }
        arr[len++] = x;
      }
      s++;
    }
    sort0(arr, len);
    len--;
    while (len >= 0) {
      ALICE += arr[len];
      len -= 2;
    }
    printf("%d\n", ALICE);
    t--;
  }
  return 0;
}
