#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
const double pi = acos(-1.0);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    vector<int> count;
    string s;
    cin >> s;
    int c = 0;
    for (int i = 0; i < s.length(); i += 1) {
      while (s[i] == '1') {
        c++;
        i++;
      }
      if (c > 0) count.push_back(c);
      c = 0;
    }
    sort(count.begin(), count.end());
    reverse(count.begin(), count.end());
    int i = 0;
    int ans = 0;
    for (auto it = count.begin(); it != count.end(); it++) {
      if (i % 2 == 0) ans += *it;
      i++;
    }
    cout << ans << endl;
  }
  return 0;
}
