#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 10;
char s[maxn];
vector<int> v;
bool cmp(int x, int y) { return x > y; }
void solve() {
  v.clear();
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  int now = 1;
  while (now <= n) {
    while (s[now] == '0' && now <= n) now++;
    int c = 0;
    while (s[now] == '1' && now <= n) c++, now++;
    v.push_back(c);
  }
  sort(v.begin(), v.end(), cmp);
  int ans = 0;
  for (int i = 0; i < v.size(); i += 2) ans += v[i];
  printf("%d\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
