#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
const int INF = 1e9 + 7;
long long res = 0;
int n, m, a[MAXN];
bool cmp(int x, int y) { return x > y; }
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    string str;
    cin >> str;
    res = 0;
    int len = str.size();
    int k = 0, c = 0;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < len; i++) {
      if (str[i] == '1') {
        k++;
      } else {
        if (k != 0) {
          c++;
          a[c] = k;
        }
        k = 0;
      }
    }
    if (k != 0) {
      c++;
      a[c] = k;
    }
    sort(a + 1, a + 1 + c, cmp);
    for (int i = 1; i <= c; i += 2) {
      res += a[i];
    }
    printf("%d\n", res);
  }
  return 0;
}
