#include <bits/stdc++.h>
using namespace std;
long long mo = 1e9 + 7;
long long i, j;
long long power(long long p, long long k) {
  long long a = 1;
  while (k) {
    if (k & 1) a = (a * p) % mo;
    p = (p * p) % mo;
    k >>= 1;
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  long long num = 1;
  while (tc--) {
    string s;
    cin >> s;
    if (s.length() <= 2)
      cout << 0;
    else {
      long long z = 0, o = 0, tz = 0, to = 0;
      long long ans = 1e18;
      for (i = 0; i < s.length(); i++) {
        if (s[i] == '0')
          tz++;
        else
          to++;
      }
      for (i = 0; i < s.length(); i++) {
        if (s[i] == '0')
          z++;
        else
          o++;
        ans = min(ans, min(z, o) + min(tz - z, to - o));
      }
      cout << ans;
    }
    cout << "\n";
  }
}
