#include <bits/stdc++.h>
using namespace std;
long long hug(long long s) {
  long long x = (s * (s + 1)) / 2;
  return x;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long n = s.length();
    long long o = 0, z = 0, f = 0;
    long long a[n];
    if (s[0] == '1')
      a[0] = 1;
    else
      a[0] = 0;
    for (int i = 1; i < n; i++) {
      if (s[i] == '1')
        a[i] = a[i - 1] + 1;
      else
        a[i] = a[i - 1];
    }
    o = a[n - 1];
    z = n - o;
    long long ans = z;
    ans = min(ans, o);
    for (int i = 0; i < n; i++) {
      long long temp = i + 1 - a[i];
      long long t2 = o - a[i];
      ans = min(ans, t2 + temp);
      temp = a[i];
      t2 = z - (i + 1 - a[i]);
      ans = min(ans, t2 + temp);
    }
    cout << ans << endl;
  }
}
