#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    char arr[105];
    scanf("%s", &arr);
    int arrlen = strlen(arr);
    int sqn[arrlen];
    for (int j = 0; j < arrlen; j++) {
      sqn[j] = 0;
    }
    int index = 0;
    for (int j = 0; j < arrlen; j++) {
      if (arr[j] == '1') {
        sqn[index]++;
        j++;
        while ((arr[j] == '1') && (j < arrlen)) {
          sqn[index]++;
          j++;
        }
        index++;
        j--;
      }
    }
    for (int j = index - 1; j >= 1; j--) {
      for (int a = 0; a < j; a++) {
        if (sqn[a] > sqn[a + 1]) {
          int temp = sqn[a];
          sqn[a] = sqn[a + 1];
          sqn[a + 1] = temp;
        }
      }
    }
    int total = 0;
    for (int j = index - 1; j >= 0; j -= 2) {
      total += sqn[j];
    }
    printf("%d\n", total);
  }
  return 0;
}
