#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = ((int)(s).size());
    int a = 0, b = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '0')
        a++;
      else
        b++;
    }
    int ans = min(a, b);
    int aa = 0, bb = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '0') {
        aa++;
        a--;
      } else {
        bb++;
        b--;
      }
      ans = min(ans, aa + b);
      ans = min(ans, bb + a);
    }
    cout << ans << "\n";
  }
  return 0;
}
