#include <bits/stdc++.h>
using namespace std;
long long int tt;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    string ch;
    cin >> ch;
    long long int n;
    n = ch.length();
    vector<long long int> pre(n + 1, 0), pre1(n + 1, 0);
    vector<long long int> suff(n + 1, 0), suff1(n + 1, 0);
    for (long long int i = 0; i < n; i++) {
      if (ch[i] == '1') {
        pre1[i] = 1;
      } else {
        pre[i] = 1;
      }
      if (i != 0) {
        pre[i] += pre[i - 1];
        pre1[i] += pre1[i - 1];
      }
    }
    for (long long int i = n - 1; i >= 0; i--) {
      if (ch[i] == '1') {
        suff1[i] = 1;
      } else {
        suff[i] = 1;
      }
      if (i != (n - 1)) {
        suff[i] += suff[i + 1];
        suff1[i] += suff1[i + 1];
      }
    }
    long long int ans;
    ans = min(suff1[0], suff[0]);
    for (long long int i = 0; i < n; i++) {
      long long int ans1;
      ans1 = min(pre1[i] + suff[i + 1], pre[i] + suff1[i + 1]);
      ans = min(ans, ans1);
    }
    cout << ans << endl;
  }
}
