#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 5;
char s[105];
int a[105], t, cnt;
int main() {
  scanf("%d", &t);
  while (t--) {
    cnt = 0;
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    int vis = 0;
    for (int i = 1; i <= n + 1; i++) {
      if (s[i] == '0' || i == n + 1) {
        if (vis) a[++cnt] = vis;
        vis = 0;
      } else
        vis++;
    }
    sort(a + 1, a + 1 + cnt);
    bool flag = 0;
    int ans = 0;
    for (int i = cnt; i >= 1; i--) {
      if (!flag) ans += a[i];
      flag ^= 1;
    }
    printf("%d\n", ans);
  }
}
