#include <bits/stdc++.h>
using namespace std;
const int inf1 = 1e9 + 9;
const long long inf2 = 1e16 + 9;
const long long mol = 1e9 + 7;
const int maxn = 5e4 + 9;
const long long maxx = 1e12 + 9;
string s;
int ans[maxn];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    cin >> s;
    int len = 0, tmp = s[0] - '0';
    for (int i = 1; s[i]; i++) {
      if (tmp && s[i] == '0')
        ans[len++] = tmp, tmp = 0;
      else if (s[i] == '1')
        tmp++;
    }
    if (tmp) ans[len++] = tmp;
    sort(ans, ans + len, greater<int>());
    int sum = 0;
    for (int i = 0; i < len; i += 2) sum += ans[i];
    printf("%d\n", sum);
  }
}
