#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long maxn = 201110;
const long long M = 1e9 + 7;
long long n;
long long a[maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    n = 0;
    long long cnt = 0;
    for (auto i : s) {
      if (i == '1')
        cnt++;
      else {
        if (cnt) a[++n] = cnt;
        cnt = 0;
      }
    }
    if (cnt) a[++n] = cnt;
    sort(a + 1, a + 1 + n, greater<long long>());
    long long ans = 0;
    for (long long i = 1; i <= n; i += 2) ans += a[i];
    cout << ans << endl;
  }
  return 0;
}
