#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long l = s.size();
    long long on = 0, z = 0;
    for (long long i = 0; i < l; i++) {
      if (s[i] == '0')
        z++;
      else
        on++;
    }
    long long x = 0, y = 0;
    long long mx = INT_MAX;
    for (long long i = 0; i < l; i++) {
      if (s[i] == '0') {
        x++;
        z--;
      } else {
        y++;
        on--;
      }
      long long mn = min(x + on, y + z);
      mx = min(mx, mn);
    }
    cout << mx << endl;
  }
}
