#include <bits/stdc++.h>
using namespace std;
int min(int x, int y) {
  if (x > y) return y;
  return x;
}
int main() {
  int t, i, j, k, v, z, l, ans, fr, bk;
  string s;
  cin >> t;
  while (t--) {
    cin >> s;
    v = 0, z = 0, ans = 0;
    l = s.size();
    int arr[l];
    if (l > 2) {
      for (i = 0; i < l; i++) {
        arr[i] = v;
        if (s[i] == '0')
          z++;
        else
          v++;
      }
      ans = min(v, z);
      for (i = 1; i < l; i++) {
        fr = min(arr[i], i - arr[i]);
        bk = min(v - arr[i], l - i - v + arr[i]);
        if (fr + bk < ans) ans = fr + bk;
      }
    }
    cout << ans << endl;
  }
}
