#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc, ti = 1;
  cin >> tc;
  while (tc--) {
    string s;
    cin >> s;
    int n = s.size(), i, z = 0, o = 0, ans = 1e9;
    vector<int> vz(n), vo(n);
    for (i = 0; i < n; ++i) {
      if (int(s[i] - '0'))
        ++o;
      else
        ++z;
      vz[i] = z;
      vo[i] = o;
    }
    ans = min(o, z);
    for (i = 0; i < n; ++i) {
      ans = min(ans, vo[i] + z - vz[i]);
      ans = min(ans, vz[i] + o - vo[i]);
    }
    cout << ans << "\n";
  }
  return 0;
}
