#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long t, n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string s;
    vector<int> v;
    int k = 0;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '1' && s[i - 1] == '0') k = i;
      if (s[i] == '0' && s[i - 1] == '1') {
        v.push_back(i - k);
        k = 0;
      }
    }
    if (s[s.size() - 1] == '1') v.push_back(s.size() - k);
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < v.size(); i += 2) ans += v[i];
    cout << ans << "\n";
  }
}
