#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 17;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[]) {
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    int n0 = 0, n1 = 0, n = s.length();
    vector<int> vz(s.length() + 2, 0);
    for (size_t i = 0; i < n; i++) {
      vz[i + 1] = vz[i];
      if (s[i] == '0') {
        n0++;
        vz[i + 1]++;
      } else {
        n1++;
      }
    }
    int ans = 0x3fffffff;
    for (size_t i = 0; i <= n; i++) {
      int l0 = vz[i], l1 = i - vz[i];
      int r0 = n0 - vz[i], r1 = n1 - l1;
      ;
      ;
      ;
      ;
      ;
      ans = min(ans, min(l1 + r0, l0 + r1));
      ;
    }
    cout << ans << endl;
  }
  return 0;
}
