#include <bits/stdc++.h>
using namespace std;
vector<int> stree, aptree;
void build_tree(vector<int>& tree, int arr[], int s, int e, int i) {
  if (s == e) {
    tree[i] = arr[s];
    return;
  }
  int mid = (s + e) / 2;
  build_tree(tree, arr, s, mid, 2 * i + 1);
  build_tree(tree, arr, mid + 1, e, 2 * i + 2);
  tree[i] = tree[2 * i + 1] + tree[2 * i + 2];
}
void updateTree(vector<int>& tree, int arr[], int s, int e, int treeIndex,
                int uIndex, int val) {
  if (s == e) {
    tree[treeIndex] = val;
    arr[s] = val;
    return;
  }
  int mid = (s + e) / 2;
  if (uIndex <= mid) {
    updateTree(tree, arr, s, mid, 2 * treeIndex + 1, uIndex, val);
  } else {
    updateTree(tree, arr, mid + 1, e, 2 * treeIndex + 2, uIndex, val);
  }
  tree[treeIndex] = tree[2 * treeIndex + 1] + tree[2 * treeIndex + 2];
}
int query(vector<int>& tree, int s, int e, int i, int qs, int qe) {
  if (qe < s || qs > e) return 0;
  if (qs <= s && qe >= e) return tree[i];
  int mid = (s + e) / 2;
  return (query(tree, s, mid, 2 * i + 1, qs, qe) +
          query(tree, mid + 1, e, 2 * i + 2, qs, qe));
}
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  int dp[2][n];
  int p = 0, abc = 0, h = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      h++;
    else
      abc++;
    dp[0][i] = p + (s[i] == '0');
    p = dp[0][i];
  }
  p = 0;
  for (int i = 0; i < n; i++) {
    dp[1][i] = p + (s[i] == '1');
    p = dp[1][i];
  }
  int manimum = min(dp[0][n - 1], dp[1][n - 1]);
  for (int i = 0; i < n - 1; i++) {
    manimum = min(manimum, dp[0][i] + abc - dp[1][i]);
    manimum = min(manimum, dp[1][i] + h - dp[0][i]);
  }
  cout << manimum << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  for (int i = 1; i < t + 1; i++) {
    solve();
  }
}
