#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int zo = 0, o, z, i, m, ans = 0;
    string s;
    cin >> s;
    long long int n = s.length();
    long long int lz[n], lo[n], rz[n], ro[n];
    lz[0] = 0;
    lo[0] = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '1')
        o++;
      else
        z++;
    }
    for (i = 1; i < n; i++) {
      if (s[i - 1] == '0') {
        lz[i] = 1 + lz[i - 1];
        lo[i] = lo[i - 1];
      } else {
        lo[i] = 1 + lo[i - 1];
        lz[i] = lz[i - 1];
      }
    }
    rz[n - 1] = 0;
    ro[n - 1] = 0;
    for (i = n - 2; i >= 0; i--) {
      if (s[i + 1] == '0') {
        rz[i] = 1 + rz[i + 1];
        ro[i] = ro[i + 1];
      } else {
        ro[i] = 1 + ro[i + 1];
        rz[i] = rz[i + 1];
      }
    }
    m = LLONG_MAX;
    for (i = 0; i < n; i++) {
      m = min(m, min(lo[i] + rz[i], lz[i] + ro[i]));
    }
    if (m > min(o, z)) {
      ans = min(o, z);
    } else
      ans = m;
    cout << ans << endl;
  }
  return 0;
}
