#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> v0(n + 1, 0), v1(n + 1, 0);
  for (int i = 1; i < n + 1; i++) {
    if (s[i - 1] == '0') {
      v0[i] = v0[i - 1] + 1;
      v1[i] = v1[i - 1];
    } else {
      v1[i] = v1[i - 1] + 1;
      v0[i] = v0[i - 1];
    }
  }
  int ans = INT_MAX;
  for (int i = 0; i < n + 1; i++) {
    ans = min(ans, v1[i] + v0[n] - v0[i]);
    ans = min(ans, v0[i] + v1[n] - v1[i]);
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  for (int i = 1; i < t + 1; i++) {
    solve();
  }
  return 0;
}
