#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long l, long long md) {
  long long res = 1;
  while (l) {
    if (l & 1) res = res * a % md;
    l /= 2;
    a = a * a % md;
  }
  return res;
}
void solve() {
  string s;
  cin >> s;
  long long o = 0, z = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      z++;
    }
    if (s[i] == '1') {
      o++;
    }
  }
  long long x = 0, y = 0, ans = 1e18;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == '0')
      x++;
    else
      y++;
    ans = min(ans, z - x + y);
    ans = min(ans, o - y + x);
  }
  cout << ans << "\n";
  return;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
